6#ifndef _ZFI_ZFImpl_ZFLua_h_
7#define _ZFI_ZFImpl_ZFLua_h_
107typedef void (*_ZFP_ZFImpl_ZFLua_ImplSetupAttach)(
111typedef void (*_ZFP_ZFImpl_ZFLua_ImplSetupDetach)(
ZF_IN_OUT lua_State *L);
112typedef void (*_ZFP_ZFImpl_ZFLua_ImplSetupClassDataUpdate)(
118 ZF_IN _ZFP_ZFImpl_ZFLua_ImplSetupAttach setupAttachCallback
119 ,
ZF_IN _ZFP_ZFImpl_ZFLua_ImplSetupDetach setupDetachCallback
120 ,
ZF_IN _ZFP_ZFImpl_ZFLua_ImplSetupClassDataUpdate setupClassDataUpdate
123 ZF_IN _ZFP_ZFImpl_ZFLua_ImplSetupAttach setupAttachCallback
124 ,
ZF_IN _ZFP_ZFImpl_ZFLua_ImplSetupDetach setupDetachCallback
125 ,
ZF_IN _ZFP_ZFImpl_ZFLua_ImplSetupClassDataUpdate setupClassDataUpdate
152#define ZFImpl_ZFLua_implSetupCallback_DEFINE(SetupSig, setupAttachAction, setupDetachAction, setupClassDataUpdate) \
153 ZF_GLOBAL_INITIALIZER_INIT_WITH_LEVEL(ZFImpl_ZFLua_implSetupAction_##SetupSig, ZFLevelZFFrameworkLow) { \
154 _ZFP_ZFImpl_ZFLua_implSetupCallbackRegister(zfself::implSetupAttach, zfself::implSetupDetach, zfself::implSetupClassDataUpdate); \
156 ZF_GLOBAL_INITIALIZER_DESTROY(ZFImpl_ZFLua_implSetupAction_##SetupSig) { \
157 _ZFP_ZFImpl_ZFLua_implSetupCallbackUnregister(zfself::implSetupAttach, zfself::implSetupDetach, zfself::implSetupClassDataUpdate); \
160 static void implSetupAttach( \
161 ZF_IN_OUT lua_State *L \
162 , ZF_IN_OUT ZFImpl_ZFLua_ImplSetupHelper &helper \
166 static void implSetupDetach(ZF_IN_OUT lua_State *L) { \
169 static void implSetupClassDataUpdate( \
170 ZF_IN_OUT lua_State *L \
171 , ZF_IN const ZFClassDataUpdateData &data \
172 , ZF_IN_OUT ZFImpl_ZFLua_ImplSetupHelper &helper \
174 setupClassDataUpdate \
176 ZF_GLOBAL_INITIALIZER_END(ZFImpl_ZFLua_implSetupAction_##SetupSig)
229 ,
ZF_IN int luaStackOffset
237 ,
ZF_IN int luaStackOffset
251 ,
ZF_IN int luaStackOffset
268 ,
ZF_IN int luaStackOffset
282 ,
ZF_IN int luaStackOffset
290 ,
ZF_IN int luaStackOffset
303 ,
ZF_IN int luaStackOffset
333 ,
ZF_IN int luaStackOffset
348 ,
ZF_IN int luaStackOffset
427 luaL_unref(
L, LUA_REGISTRYINDEX,
luaValue);
437 lua_rawgeti(
L, LUA_REGISTRYINDEX,
luaValue);
449 return ELuna::openLua();
462 ELuna::registerClass<T>(L, name, ELuna::constructor<zfauto>);
471 ELuna::registerFunction(L, name, f);
477 ,
ZF_IN int (*f)(lua_State *)
479 lua_register(L, name, f);
491 ELuna::convert2LuaType<zfauto>::convertType(L, v);
512 ,
ZF_IN int luaStackOffset
514 return ELuna::convert2CppType<zfauto &>::convertType(L, luaStackOffset);
543#define ZFImpl_ZFLua_luaErrorPrepare(L) \
544 _ZFP_ZFImpl_ZFLua_luaErrorPrepare _ZFP_ZFImpl_ZFLua_luaErrorPrepareNotCalled(L)
547 _ZFP_ZFImpl_ZFLua_luaErrorPrepare(
ZF_IN lua_State *L)
552 ~_ZFP_ZFImpl_ZFLua_luaErrorPrepare(
void) {
553 if(this->errorHint) {
555 for(
int iStack = 1; ; ++iStack) {
556 int success = lua_getstack(L, iStack, &ar);
560 success = lua_getinfo(L,
"nSl", &ar);
564 if((iStack == 2 || ar.name == NULL) && ar.currentline > 0) {
566 this->errorHint.insert(0,
zfstr(
"<<{{%s}}>>", (
zfindex)ar.currentline));
573 this->errorHint +=
"\n";
574 this->errorHint += info;
576 luaL_error(L,
"%s", this->errorHint.cString());
585 this->errorHint += text;
594#define ZFImpl_ZFLua_luaError(L, fmt, ...) \
595 _ZFP_ZFImpl_ZFLua_luaErrorPrepareNotCalled.luaError(L, zfstr(fmt, ##__VA_ARGS__))
603 _ZFP_ZFLuaStackChecker(
607 : L(L), stackChange(stackChange), stackSaved(lua_gettop(L))
610 ~_ZFP_ZFLuaStackChecker(
void) {
611 int cur = lua_gettop(L);
613 cur == stackSaved + stackChange,
614 "stack messed up: %s(%s) => %s",
615 stackSaved, stackChange, cur);
620 #define ZFImpl_ZFLua_DEBUG_luaStackChecker(name, L, stackChange) \
621 _ZFP_ZFLuaStackChecker _DEBUG_luaStackChecker_##name(L, stackChange)
623 #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:208
#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:196
#define ZF_IN_OPT
dummy macro that shows the param used as optional input
Definition ZFCoreTypeDef_ClassType.h:200
#define ZF_OUT
dummy macro that shows the param used as required output
Definition ZFCoreTypeDef_ClassType.h:204
#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:212
_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:217
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:301
lua_State * ZFImpl_ZFLua_luaOpen(void)
util for impl
Definition ZFImpl_ZFLua.h:448
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:474
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:452
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:483
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:346
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
ZFPathInfo ZFImpl_ZFLua_localPathInfoDetect(lua_State *L)
try to detect local path info for current context
zfauto & ZFImpl_ZFLua_luaGet(lua_State *L, int luaStackOffset)
util for impl
Definition ZFImpl_ZFLua.h:510
void ZFImpl_ZFLua_luaClassRegister(lua_State *L, const zfchar *name)
util for impl
Definition ZFImpl_ZFLua.h:458
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:466
zfstring ZFImpl_ZFLua_luaObjectInfo(lua_State *L, int luaStackOffset, zfbool printLuaType=_ZFT_t_zffalse)
get raw lua object info
Definition ZFImpl_ZFLua.h:235
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 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:122
data holder for ZFGlobalEvent::E_ClassDataUpdate
Definition ZFObjectClassTypeFwd.h:144
ZFObject's class info.
Definition ZFClass.h:63
light weight array
Definition ZFCoreArray.h:292
see ZFImpl_ZFLua_luaStateOpen
Definition ZFImpl_ZFLua.h:73
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:410
virtual void objectOnDeallocPrepare(void)
called before objectOnDealloc, safe to call virtual functions here
Definition ZFImpl_ZFLua.h:425
virtual zfbool objectIsInternalPrivate(void)
whether this object is internal private object or its class is ZFClass::classIsInternalPrivate
Definition ZFImpl_ZFLua.h:416
virtual zfbool objectIsInternal(void)
whether this object is internal object or its class is ZFClass::classIsInternal
Definition ZFImpl_ZFLua.h:414
virtual void objectOnInit(void)
override this to init your object
Definition ZFImpl_ZFLua.h:419
lua_State * L
the lua state
Definition ZFImpl_ZFLua.h:409
virtual void objectInfoImplAppend(zfstring &ret)
see objectInfo
Definition ZFImpl_ZFLua.h:434
base class of all objects
Definition ZFObjectCore.h:195
virtual void objectOnInit(void)
override this to init your object
virtual void objectInfoImplAppend(zfstring &ret)
see objectInfo
Definition ZFObjectCore.h:320
virtual void objectOnDeallocPrepare(void)
called before objectOnDealloc, safe to call virtual functions here
Definition ZFObjectCore.h:746
path related info storage for impl, actual meaning of the info depends on impl
Definition ZFPathInfo.h:34
type wrapper for ZFTypeId::Value
Definition ZFTypeId_CoreType.h:124
static const ZFClass * ClassData(void)
get class info
Definition ZFTypeId_CoreType.h:124
a ZFObject holder which would release content object automatically when destroyed
Definition zfautoFwd.h:34
#define zfcast(T_To, obj)
safely cast ZFObject types, return null if not desired type
Definition zfcast.h:24
zfstring zfstr(const zfchar *fmt=zft_zfnull)
string format util
Definition zfstr.h:59