global header for lua impl More...
Go to the source code of this file.
Classes | |
| class | ZFImpl_ZFLua_ImplSetupHelper |
| see ZFImpl_ZFLua_luaStateOpen More... | |
| class | ZFImpl_ZFLuaValue |
| raw lua value created by ZFImpl_ZFLua_toGeneric, and can be converted by ZFImpl_ZFLua_toLuaValue More... | |
Macros | |
| #define | ZFImpl_ZFLua_implSetupCallback_DEFINE(SetupSig, setupAttachAction, setupDetachAction, setupClassDataUpdate) |
| for impl to add attach and detach actions | |
| #define | ZFImpl_ZFLua_luaErrorPrepare(L) |
| util for impl | |
| #define | ZFImpl_ZFLua_luaError(L, fmt, ...) |
| see ZFImpl_ZFLua_luaErrorPrepare | |
| #define | ZFImpl_ZFLua_DEBUG_luaStackChecker(name, L, stackChange) |
| util to debug lua stack, assert fail if stack messed up | |
Functions | |
| void * | ZFImpl_ZFLua_luaStateOpen (void) |
| create new lua state | |
| void | ZFImpl_ZFLua_luaStateClose (lua_State *L) |
| see ZFImpl_ZFLua_luaStateOpen | |
| void | ZFImpl_ZFLua_luaStateAttach (lua_State *L) |
| see ZFImpl_ZFLua_luaStateOpen | |
| void | ZFImpl_ZFLua_luaStateDetach (lua_State *L) |
| see ZFImpl_ZFLua_luaStateAttach | |
| void | ZFImpl_ZFLua_classDataUpdate (lua_State *L, const ZFClassDataUpdateData &data) |
| called when class data changed, for each lua state of each thread | |
| void | ZFImpl_ZFLua_implSetupMetatable (lua_State *L, int metatableIndex=-1) |
| setup metatable for zfauto in lua env | |
| zfbool | ZFImpl_ZFLua_execute (lua_State *L, const zfchar *buf, zfindex bufLen=((zfindex) -1), zfauto *luaResult=zft_zfnull, const ZFCoreArray< zfauto > *luaParams=zft_zfnull, zfstring *errHint=zft_zfnull, const zfchar *chunkInfo=zft_zfnull, const zfchar *srcInfo=zft_zfnull) |
| run lua code, L must be first initialized by ZFImpl_ZFLua_luaStateAttach | |
| void | ZFImpl_ZFLua_execute_errorHandle (lua_State *L, int error, zfstring *errHint=zft_zfnull, const zfchar *chunkInfo=zft_zfnull, zfindex errorLine=((zfindex) -1)) |
| error handler for ZFImpl_ZFLua_execute, lua_pcall, etc | |
| zfbool | ZFImpl_ZFLua_stacktraceT (lua_State *L, zfstring &ret) |
| get lua stacktrace | |
| zfstring | ZFImpl_ZFLua_stacktrace (lua_State *L) |
| get lua stacktrace | |
| void | ZFImpl_ZFLua_luaObjectInfoT (zfstring &ret, lua_State *L, int luaStackOffset, zfbool printLuaType=_ZFT_t_zffalse) |
| see ZFImpl_ZFLua_luaObjectInfo | |
| zfstring | ZFImpl_ZFLua_luaObjectInfo (lua_State *L, int luaStackOffset, zfbool printLuaType=_ZFT_t_zffalse) |
| get raw lua object info | |
| zfbool | ZFImpl_ZFLua_toObject (zfauto ¶m, lua_State *L, int luaStackOffset) |
| get params from lua | |
| zfbool | ZFImpl_ZFLua_toGeneric (zfauto ¶m, lua_State *L, int luaStackOffset, zfstring *errorHint=zft_zfnull) |
| get params from lua | |
| zfbool | ZFImpl_ZFLua_toCallback (zfauto &ret, lua_State *L, int luaStackOffset, zfstring *errorHint=zft_zfnull) |
| get params from lua | |
| zfbool | ZFImpl_ZFLua_toStringT (zfstring &s, lua_State *L, int luaStackOffset, zfbool allowEmpty=_ZFT_t_zffalse, const ZFClass **holderCls=zft_zfnull) |
| see ZFImpl_ZFLua_toString | |
| zfstring | ZFImpl_ZFLua_toString (lua_State *L, int luaStackOffset, zfbool allowEmpty=_ZFT_t_zffalse, const ZFClass **holderCls=zft_zfnull) |
| get params from lua | |
| zfbool | ZFImpl_ZFLua_toStringT (zfstring &s, ZFObject *obj, zfbool allowEmpty=_ZFT_t_zffalse, const ZFClass **holderCls=zft_zfnull) |
| see ZFImpl_ZFLua_toString | |
| zfstring | ZFImpl_ZFLua_toString (ZFObject *obj, zfbool allowEmpty=_ZFT_t_zffalse, const ZFClass **holderCls=zft_zfnull) |
| see ZFImpl_ZFLua_toString | |
| zfbool | ZFImpl_ZFLua_toNumberT (zfauto &ret, lua_State *L, int luaStackOffset, zfbool allowEmpty=_ZFT_t_zffalse, const ZFClass **holderCls=zft_zfnull) |
| see ZFImpl_ZFLua_toNumber | |
| zfauto | ZFImpl_ZFLua_toNumber (lua_State *L, int luaStackOffset, zfbool allowEmpty=_ZFT_t_zffalse, const ZFClass **holderCls=zft_zfnull) |
| get params from lua | |
| zfbool | ZFImpl_ZFLua_toNumberT (zfauto &ret, ZFObject *obj, zfbool allowEmpty=_ZFT_t_zffalse, const ZFClass **holderCls=zft_zfnull) |
| see ZFImpl_ZFLua_toNumber | |
| zfbool | ZFImpl_ZFLua_toLuaValue (lua_State *L, ZFObject *obj, zfbool allowEmpty=_ZFT_t_zffalse) |
| convert native type to lua type | |
| zfbool | ZFImpl_ZFLua_zfstringAppend (lua_State *L, zfstring &s, int luaParamOffset=1) |
| append with va_arg, see ZFLuaExecute | |
| zfstring | ZFImpl_ZFLua_luaStackInfo (lua_State *L, int luaStackOffset=1) |
| return info of current stack | |
| lua_State * | ZFImpl_ZFLua_luaOpen (void) |
| util for impl | |
| void | ZFImpl_ZFLua_luaClose (lua_State *L) |
| util for impl | |
| template<typename T> | |
| void | ZFImpl_ZFLua_luaClassRegister (lua_State *L, const zfchar *name) |
| util for impl | |
| template<typename F> | |
| void | ZFImpl_ZFLua_luaFunctionRegister (lua_State *L, const zfchar *name, F f) |
| util for impl | |
| void | ZFImpl_ZFLua_luaCFunctionRegister (lua_State *L, const zfchar *name, int(*f)(lua_State *)) |
| util for impl | |
| void | ZFImpl_ZFLua_luaPush (lua_State *L, zfauto &v) |
| util for impl | |
| void | ZFImpl_ZFLua_luaPush (lua_State *L, const zfauto &v) |
| util for impl | |
| void | ZFImpl_ZFLua_luaPush (lua_State *L, ZFObject *v) |
| util for impl | |
| zfauto & | ZFImpl_ZFLua_luaGet (lua_State *L, int luaStackOffset) |
| util for impl | |
global header for lua impl
| #define ZFImpl_ZFLua_implSetupCallback_DEFINE | ( | SetupSig, | |
| setupAttachAction, | |||
| setupDetachAction, | |||
| setupClassDataUpdate ) |
for impl to add attach and detach actions
usage:
| #define ZFImpl_ZFLua_luaErrorPrepare | ( | L | ) |
util for impl
used to solve this problem: when raise lua error without ZF_ENV_ZFLUA_USE_EXCEPTION defined, you must ensure any cpp object has been properly cleaned up (from nearest lua c function registered by ZFImpl_ZFLua_luaCFunctionRegister, to luaL_error), otherwise all of cpp objects' destructor would be skipped due to usage of longjmp instead of exception handler
a typical recommended use case:
|
extern |
create new lua state
how the impl works:
MyClass.myFunc(param);zfl_call(zfnull, "MyClass.myFunc", param);local cls = MyClass; cls.myFunc(param);obj:myFunc(param), which equals to obj.myFunc(obj, param)
|
extern |
must not be attached more than one time
|
extern |
see ZFImpl_ZFLua_luaStateAttach
note, this method only detach L from ZFFramework, all methods registered to L can not be undo
|
extern |
run lua code, L must be first initialized by ZFImpl_ZFLua_luaStateAttach
NOTE: the lua code can return any number of values (any type that ZFImpl_ZFLua_toGeneric supports), when more than one value returned, the luaResult would holds a v_ZFCoreArray
|
extern |
get params from lua
supports these types:
|
extern |
get params from lua
supports these types:
|
inline |
get params from lua
support types:
return proper v_zfdouble if success, or empty if fail
|
extern |
convert native type to lua type
support all types that can be converted by:
if success, push result value to top of lua's stack and return true, otherwise, push nothing and return false
if allowEmpty, push 0 number if obj is null