6#ifndef _ZFI_ZFImpl_ZFLua_h_
7#define _ZFI_ZFImpl_ZFLua_h_
100typedef void (*_ZFP_ZFImpl_ZFLua_ImplSetupAttach)(
104typedef void (*_ZFP_ZFImpl_ZFLua_ImplSetupDetach)(
ZF_IN_OUT lua_State *L);
105typedef void (*_ZFP_ZFImpl_ZFLua_ImplSetupClassDataUpdate)(
111 ZF_IN _ZFP_ZFImpl_ZFLua_ImplSetupAttach setupAttachCallback
112 ,
ZF_IN _ZFP_ZFImpl_ZFLua_ImplSetupDetach setupDetachCallback
113 ,
ZF_IN _ZFP_ZFImpl_ZFLua_ImplSetupClassDataUpdate setupClassDataUpdate
116 ZF_IN _ZFP_ZFImpl_ZFLua_ImplSetupAttach setupAttachCallback
117 ,
ZF_IN _ZFP_ZFImpl_ZFLua_ImplSetupDetach setupDetachCallback
118 ,
ZF_IN _ZFP_ZFImpl_ZFLua_ImplSetupClassDataUpdate setupClassDataUpdate
145#define ZFImpl_ZFLua_implSetupCallback_DEFINE(SetupSig, setupAttachAction, setupDetachAction, setupClassDataUpdate) \
146 ZF_GLOBAL_INITIALIZER_INIT_WITH_LEVEL(ZFImpl_ZFLua_implSetupAction_##SetupSig, ZFLevelZFFrameworkLow) { \
147 _ZFP_ZFImpl_ZFLua_implSetupCallbackRegister(zfself::implSetupAttach, zfself::implSetupDetach, zfself::implSetupClassDataUpdate); \
149 ZF_GLOBAL_INITIALIZER_DESTROY(ZFImpl_ZFLua_implSetupAction_##SetupSig) { \
150 _ZFP_ZFImpl_ZFLua_implSetupCallbackUnregister(zfself::implSetupAttach, zfself::implSetupDetach, zfself::implSetupClassDataUpdate); \
153 static void implSetupAttach( \
154 ZF_IN_OUT lua_State *L \
155 , ZF_IN_OUT ZFImpl_ZFLua_ImplSetupHelper &helper \
159 static void implSetupDetach(ZF_IN_OUT lua_State *L) { \
162 static void implSetupClassDataUpdate( \
163 ZF_IN_OUT lua_State *L \
164 , ZF_IN const ZFClassDataUpdateData &data \
165 , ZF_IN_OUT ZFImpl_ZFLua_ImplSetupHelper &helper \
167 setupClassDataUpdate \
169 ZF_GLOBAL_INITIALIZER_END(ZFImpl_ZFLua_implSetupAction_##SetupSig)
222 ,
ZF_IN int luaStackOffset
230 ,
ZF_IN int luaStackOffset
244 ,
ZF_IN int luaStackOffset
261 ,
ZF_IN int luaStackOffset
275 ,
ZF_IN int luaStackOffset
283 ,
ZF_IN int luaStackOffset
296 ,
ZF_IN int luaStackOffset
326 ,
ZF_IN int luaStackOffset
341 ,
ZF_IN int luaStackOffset
420 luaL_unref(
L, LUA_REGISTRYINDEX,
luaValue);
430 lua_rawgeti(
L, LUA_REGISTRYINDEX,
luaValue);
442 return ELuna::openLua();
455 ELuna::registerClass<T>(L, name, ELuna::constructor<zfauto>);
464 ELuna::registerFunction(L, name, f);
470 ,
ZF_IN int (*f)(lua_State *)
472 lua_register(L, name, f);
484 ELuna::convert2LuaType<zfauto>::convertType(L, v);
505 ,
ZF_IN int luaStackOffset
507 return ELuna::convert2CppType<zfauto &>::convertType(L, luaStackOffset);
536#define ZFImpl_ZFLua_luaErrorPrepare(L) \
537 _ZFP_ZFImpl_ZFLua_luaErrorPrepare _ZFP_ZFImpl_ZFLua_luaErrorPrepareNotCalled(L)
540 _ZFP_ZFImpl_ZFLua_luaErrorPrepare(
ZF_IN lua_State *L)
545 ~_ZFP_ZFImpl_ZFLua_luaErrorPrepare(
void) {
546 if(this->errorHint) {
548 for(
int iStack = 1; ; ++iStack) {
549 int success = lua_getstack(L, iStack, &ar);
553 success = lua_getinfo(L,
"nSl", &ar);
557 if((iStack == 2 || ar.name == NULL) && ar.currentline > 0) {
559 this->errorHint.insert(0,
zfstr(
"<<{{%s}}>>", (
zfindex)ar.currentline));
566 this->errorHint +=
"\n";
567 this->errorHint += info;
569 luaL_error(L,
"%s", this->errorHint.cString());
578 this->errorHint += text;
587#define ZFImpl_ZFLua_luaError(L, fmt, ...) \
588 _ZFP_ZFImpl_ZFLua_luaErrorPrepareNotCalled.luaError(L, zfstr(fmt, ##__VA_ARGS__))
596 _ZFP_ZFLuaStackChecker(
600 : L(L), stackChange(stackChange), stackSaved(lua_gettop(L))
603 ~_ZFP_ZFLuaStackChecker(
void) {
604 int cur = lua_gettop(L);
606 cur == stackSaved + stackChange,
607 "stack messed up: %s(%s) => %s",
608 stackSaved, stackChange, cur);
613 #define ZFImpl_ZFLua_DEBUG_luaStackChecker(name, L, stackChange) \
614 _ZFP_ZFLuaStackChecker _DEBUG_luaStackChecker_##name(L, stackChange)
616 #define ZFImpl_ZFLua_DEBUG_luaStackChecker(name, L, stackChange)
#define ZFCoreAssertWithMessageTrim(exp, fmt,...)
see ZFCoreAssertWithMessage
Definition ZFCoreLog_CommonLog.h:81
#define ZFCoreAssert(exp)
assert exp is zftrue
Definition ZFCoreLog_CommonLog.h:47
_ZFT_t_zfchar zfchar
char wrapper
Definition ZFCoreTypeDef_CharType.h:17
#define ZF_OUT_OPT
dummy macro that shows the param used as optional output
Definition ZFCoreTypeDef_ClassType.h:192
#define zfclassLikePOD
shows the class is not a POD type, but you may use it like a POD except memset it to 0
Definition ZFCoreTypeDef_ClassType.h:41
#define zfextend
dummy macro shows class inherit from another
Definition ZFCoreTypeDef_ClassType.h:53
#define zfoverride
dummy macro shows that method override parent's method
Definition ZFCoreTypeDef_ClassType.h:58
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:180
#define ZF_IN_OPT
dummy macro that shows the param used as optional input
Definition ZFCoreTypeDef_ClassType.h:184
#define ZF_OUT
dummy macro that shows the param used as required output
Definition ZFCoreTypeDef_ClassType.h:188
#define zfclassNotPOD
shows the class is not a POD type, you should not memset it or declare it in stack or copy value by c...
Definition ZFCoreTypeDef_ClassType.h:48
#define ZF_IN_OUT
dummy macro that shows the param used as required input and output
Definition ZFCoreTypeDef_ClassType.h:196
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
_ZFT_t_zfindex zfindex
similar to size_t, used for index and size only
Definition ZFCoreTypeDef_CoreType.h:154
#define zftrue
bool true type
Definition ZFCoreTypeDef_CoreType.h:107
#define zfindexMax()
(zfindex)-1, indicate a max index value, see zfindex
Definition ZFCoreTypeDef_CoreType.h:159
#define zffalse
bool false type
Definition ZFCoreTypeDef_CoreType.h:111
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
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_classDataUpdate(lua_State *L, const ZFClassDataUpdateData &data)
called when class data changed, for each lua state of each thread
void ZFImpl_ZFLua_luaStateAttach(lua_State *L)
see ZFImpl_ZFLua_luaStateOpen
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_zfstringAppend(lua_State *L, zfstring &s, int luaParamOffset=1)
append with va_arg, see ZFLuaExecute
void ZFImpl_ZFLua_implSetupMetatable(lua_State *L, int metatableIndex=-1)
setup metatable for zfauto in lua env
zfstring ZFImpl_ZFLua_luaStackInfo(lua_State *L, int luaStackOffset=1)
return info of current stack
zfstring ZFImpl_ZFLua_stacktrace(lua_State *L)
get lua stacktrace
Definition ZFImpl_ZFLua.h:210
void ZFImpl_ZFLua_luaStateDetach(lua_State *L)
see ZFImpl_ZFLua_luaStateAttach
zfbool ZFImpl_ZFLua_toGeneric(zfauto ¶m, lua_State *L, int luaStackOffset, zfstring *errorHint=zft_zfnull)
get params from lua
zfstring ZFImpl_ZFLua_toString(lua_State *L, int luaStackOffset, zfbool allowEmpty=_ZFT_t_zffalse, const ZFClass **holderCls=zft_zfnull)
get params from lua
Definition ZFImpl_ZFLua.h:294
lua_State * ZFImpl_ZFLua_luaOpen(void)
util for impl
Definition ZFImpl_ZFLua.h:441
void ZFImpl_ZFLua_luaStateClose(lua_State *L)
see ZFImpl_ZFLua_luaStateOpen
zfbool ZFImpl_ZFLua_toLuaValue(lua_State *L, ZFObject *obj, zfbool allowEmpty=_ZFT_t_zffalse)
convert native type to lua type
void ZFImpl_ZFLua_luaCFunctionRegister(lua_State *L, const zfchar *name, int(*f)(lua_State *))
util for impl
Definition ZFImpl_ZFLua.h:467
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
zfbool ZFImpl_ZFLua_toCallback(zfauto &ret, lua_State *L, int luaStackOffset, zfstring *errorHint=zft_zfnull)
get params from lua
void ZFImpl_ZFLua_luaClose(lua_State *L)
util for impl
Definition ZFImpl_ZFLua.h:445
zfbool ZFImpl_ZFLua_stacktraceT(lua_State *L, zfstring &ret)
get lua stacktrace
void ZFImpl_ZFLua_luaPush(lua_State *L, zfauto &v)
util for impl
Definition ZFImpl_ZFLua.h:476
zfauto ZFImpl_ZFLua_toNumber(lua_State *L, int luaStackOffset, zfbool allowEmpty=_ZFT_t_zffalse, const ZFClass **holderCls=zft_zfnull)
get params from lua
Definition ZFImpl_ZFLua.h:339
void * ZFImpl_ZFLua_luaStateOpen(void)
create new lua state
void ZFImpl_ZFLua_luaObjectInfoT(zfstring &ret, lua_State *L, int luaStackOffset, zfbool printLuaType=_ZFT_t_zffalse)
see ZFImpl_ZFLua_luaObjectInfo
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_luaGet(lua_State *L, int luaStackOffset)
util for impl
Definition ZFImpl_ZFLua.h:503
void ZFImpl_ZFLua_luaClassRegister(lua_State *L, const zfchar *name)
util for impl
Definition ZFImpl_ZFLua.h:451
zfbool ZFImpl_ZFLua_toObject(zfauto ¶m, lua_State *L, int luaStackOffset)
get params from lua
void ZFImpl_ZFLua_luaFunctionRegister(lua_State *L, const zfchar *name, F f)
util for impl
Definition ZFImpl_ZFLua.h:459
zfstring ZFImpl_ZFLua_luaObjectInfo(lua_State *L, int luaStackOffset, zfbool printLuaType=_ZFT_t_zffalse)
get raw lua object info
Definition ZFImpl_ZFLua.h:228
global header for ZFLua_impl module
#define ZFLIB_ZFLua_impl
used to export symbols
Definition ZFImpl_ZFLua_impl.h:16
header file for ZFLua module
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
#define zfcast(T_To, obj)
safely cast ZFObject types, return null if not desired type
Definition ZFObjectCast.h:28
#define zfclass
same as class, shows that this class is a ZFObject type
Definition ZFObjectClassTypeFwd.h:38
#define ZFOBJECT_DECLARE(ChildClass, SuperClass,...)
necessary for every class inherit from ZFObject
Definition ZFObjectDeclare.h:126
data holder for ZFGlobalEvent::E_ClassDataUpdate
Definition ZFObjectClassTypeFwd.h:143
ZFObject's class info.
Definition ZFClass.h:67
light weight array
Definition ZFCoreArray.h:331
see ZFImpl_ZFLua_luaStateOpen
Definition ZFImpl_ZFLua.h:66
void addGenericScope(const zfstring &genericScope)
see ZFImpl_ZFLua_luaStateOpen
void addCustomCode(const zfstring &code)
see ZFImpl_ZFLua_luaStateOpen
void addGlobalScope(const zfstring &scope)
see ZFImpl_ZFLua_luaStateOpen
int luaValue
the lua value ref
Definition ZFImpl_ZFLua.h:403
virtual void objectOnDeallocPrepare(void)
called before objectOnDealloc, safe to call virtual functions here
Definition ZFImpl_ZFLua.h:418
virtual zfbool objectIsInternalPrivate(void)
whether this object is internal private object or its class is ZFClass::classIsInternalPrivate
Definition ZFImpl_ZFLua.h:409
virtual zfbool objectIsInternal(void)
whether this object is internal object or its class is ZFClass::classIsInternal
Definition ZFImpl_ZFLua.h:407
virtual void objectOnInit(void)
override this to init your object
Definition ZFImpl_ZFLua.h:412
lua_State * L
the lua state
Definition ZFImpl_ZFLua.h:402
virtual void objectInfoImplAppend(zfstring &ret)
see objectInfo
Definition ZFImpl_ZFLua.h:427
base class of all objects
Definition ZFObjectCore.h:209
virtual void objectOnInit(void)
override this to init your object
virtual void objectInfoImplAppend(zfstring &ret)
see objectInfo
Definition ZFObjectCore.h:331
virtual void objectOnDeallocPrepare(void)
called before objectOnDealloc, safe to call virtual functions here
Definition ZFObjectCore.h:758
type wrapper for ZFTypeId::Value
Definition ZFTypeId_CoreType.h:128
static const ZFClass * ClassData(void)
get class info
Definition ZFTypeId_CoreType.h:128
a ZFObject holder which would release content object automatically when destroyed
Definition zfautoFwd.h:34
zfstring zfstr(const zfchar *fmt=zft_zfnull)
string format util
Definition zfstr.h:59