Ref* CustomGUIReader::createInstance() { Ref* result = nullptr; LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->executeFunction(_createFunc, 0, 1, [&result](lua_State* L,int numReturn){ result = static_cast<Ref*>(tolua_tousertype(L, -1, nullptr)); lua_pop(L, 1); }); return result; }
// 不在LuaStack类中增加接口了。 // 带参数(参数已经push好)执行全局lua函数,忽略返回值。 static void executeLuaGlobalFunction(const char* functionName,int numArgs) { LuaStack* ls = LuaEngine::getInstance()->getLuaStack(); lua_State* L = ls->getLuaState(); lua_getglobal(L,functionName); if(!lua_isfunction(L,-1)) { CCLOG("[LUA ERROR] name '%s' does not represent a Lua function",functionName); lua_settop(L,0); return; } if(numArgs>0) { lua_insert(L,-numArgs-1); } ls->executeFunction(numArgs); }