Fix lua state usage

This commit is contained in:
halx99 2021-11-15 19:05:08 +08:00
parent 3b69d0cb27
commit f7128789a0
11 changed files with 117 additions and 89 deletions

View File

@ -105,11 +105,14 @@ int lua_cocos2dx_3d_Sprite3D_createAsync(lua_State* L)
#endif
LUA_FUNCTION handler = toluafix_ref_function(L,4,0);
cocos2d::Sprite3D::createAsync(modelPath, texturePath, [=](cocos2d::Sprite3D* sprite, void* callbackparam){
cocos2d::Sprite3D::createAsync(
modelPath, texturePath,
[=](cocos2d::Sprite3D* sprite, void* callbackparam) {
auto stack = LuaEngine::getInstance()->getLuaStack();
int id = (sprite) ? (int)sprite->_ID : -1;
int* luaID = (sprite) ? &sprite->_luaID : nullptr;
toluafix_pushusertype_ccobject(L, id, luaID, (void*)sprite,"cc.Sprite3D");
LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 1);
toluafix_pushusertype_ccobject(stack->getLuaState(), id, luaID, (void*)sprite, "cc.Sprite3D");
stack->executeFunctionByHandler(handler, 1);
}, nullptr);
lua_settop(L, 1);
@ -134,10 +137,11 @@ int lua_cocos2dx_3d_Sprite3D_createAsync(lua_State* L)
LUA_FUNCTION handler = toluafix_ref_function(L, 3, 0);
cocos2d::Sprite3D::createAsync(modelPath, [=](cocos2d::Sprite3D* sprite, void* callbackparam){
auto stack = LuaEngine::getInstance()->getLuaStack();
int id = (sprite) ? (int)sprite->_ID : -1;
int* luaID = (sprite) ? &sprite->_luaID : nullptr;
toluafix_pushusertype_ccobject(L, id, luaID, (void*)sprite,"cc.Sprite3D");
LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 1);
toluafix_pushusertype_ccobject(stack->getLuaState(), id, luaID, (void*)sprite, "cc.Sprite3D");
stack->executeFunctionByHandler(handler, 1);
}, nullptr);
lua_settop(L, 1);

View File

@ -262,7 +262,7 @@ int lua_cocos2dx_audioengine_AudioEngine_setFinishCallback(lua_State* tolua_S)
LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,3,0));
cocos2d::AudioEngine::setFinishCallback(arg0, [handler](int audioID, std::string filePath){
cocos2d::AudioEngine::setFinishCallback(arg0, [=](int audioID, std::string filePath){
LuaStack* stack = LuaEngine::getInstance()->getLuaStack();
stack->pushInt(audioID);
@ -270,7 +270,7 @@ int lua_cocos2dx_audioengine_AudioEngine_setFinishCallback(lua_State* tolua_S)
stack->executeFunctionByHandler(handler, 2);
LuaEngine::getInstance()->removeScriptHandler(handler);
toluafix_remove_function_by_refid(tolua_S, handler);
});
return 0;

View File

@ -2207,14 +2207,15 @@ static int lua_cocos2dx_Node_enumerateChildren(lua_State* tolua_S)
LUA_FUNCTION handler = toluafix_ref_function(tolua_S,3,0);
cobj->enumerateChildren(name, [=](Node* node)->bool{
auto stack = LuaEngine::getInstance()->getLuaStack();
int id = node ? (int)node->_ID : -1;
int* luaID = node ? &node->_luaID : nullptr;
toluafix_pushusertype_ccobject(tolua_S, id, luaID, (void*)node,"cc.Node");
bool ret = LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 1);
toluafix_pushusertype_ccobject(stack->getLuaState(), id, luaID, (void*)node, "cc.Node");
bool ret = stack->executeFunctionByHandler(handler, 1);
return ret;
});
LuaEngine::getInstance()->removeScriptHandler(handler);
toluafix_remove_function_by_refid(tolua_S, handler);
lua_settop(tolua_S, 1);
return 1;
}
@ -5898,11 +5899,13 @@ static int lua_cocos2dx_Console_addCommand(lua_State* tolua_S)
help,
[=](int fd, const std::string& args)
{
auto stack = LuaEngine::getInstance()->getLuaStack();
auto Ls = stack->getLuaState();
//lua-callback, the third param;
tolua_pushnumber(tolua_S, fd);
tolua_pushstring(tolua_S, args.c_str());
tolua_pushnumber(Ls, fd);
tolua_pushstring(Ls, args.c_str());
LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2);
stack->executeFunctionByHandler(handler, 2);
}
};
cobj->addCommand(outValue);
@ -6375,11 +6378,12 @@ static int lua_cocos2dx_TextureCache_addImageAsync(lua_State* tolua_S)
self->addImageAsync(configFilePath, [=](Texture2D* tex){
auto stack = LuaEngine::getInstance()->getLuaStack();
int ID = (tex) ? (int)tex->_ID : -1;
int* luaID = (tex) ? &tex->_luaID : nullptr;
toluafix_pushusertype_ccobject(tolua_S, ID, luaID, (void*)tex, "cc.Texture2D");
LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler,1);
LuaEngine::getInstance()->removeScriptHandler(handler);
toluafix_pushusertype_ccobject(stack->getLuaState(), ID, luaID, (void*)tex, "cc.Texture2D");
stack->executeFunctionByHandler(handler, 1);
toluafix_remove_function_by_refid(tolua_S, handler);
});
return 0;
@ -7195,11 +7199,12 @@ static int tolua_cocos2d_utils_captureScreen(lua_State* tolua_S)
LUA_FUNCTION handler = toluafix_ref_function(tolua_S,2,0);
std::string fileName = tolua_tocppstring(tolua_S, 3, "");
cocos2d::utils::captureScreen([=](bool succeed, const std::string& name ){
tolua_pushboolean(tolua_S, succeed);
tolua_pushstring(tolua_S, name.c_str());
LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2);
LuaEngine::getInstance()->removeScriptHandler(handler);
auto stack = LuaEngine::getInstance()->getLuaStack();
auto Ls = stack->getLuaState();
tolua_pushboolean(Ls, succeed);
tolua_pushstring(Ls, name.c_str());
stack->executeFunctionByHandler(handler, 2);
toluafix_remove_function_by_refid(tolua_S, handler);
}, fileName);
return 0;

View File

@ -181,11 +181,12 @@ int lua_cocos2dx_physics_PhysicsWorld_rayCast(lua_State* tolua_S)
cocos2d::Vec2 arg2;
LUA_FUNCTION handler = toluafix_ref_function(tolua_S, 2, 0);
do {
arg0 = [handler, tolua_S](cocos2d::PhysicsWorld &world, const cocos2d::PhysicsRayCastInfo &info, void * data) -> bool
{
tolua_pushusertype(tolua_S, (void*)(&world), getLuaTypeName(&world, "cc.PhysicsWorld"));
physics_raycastinfo_to_luaval(tolua_S, info);
return LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2);
arg0 = [handler](cocos2d::PhysicsWorld &world, const cocos2d::PhysicsRayCastInfo &info, void * data) -> bool {
auto stack = LuaEngine::getInstance()->getLuaStack();
auto Ls = stack->getLuaState();
tolua_pushusertype(Ls, (void*)(&world), getLuaTypeName(&world, "cc.PhysicsWorld"));
physics_raycastinfo_to_luaval(Ls, info);
return stack->executeFunctionByHandler(handler, 2);
};
} while(0);
@ -239,11 +240,13 @@ int lua_cocos2dx_physics_PhysicsWorld_queryRect(lua_State* tolua_S)
cocos2d::Rect arg1;
LUA_FUNCTION handler = toluafix_ref_function(tolua_S, 2, 0);
do {
arg0 = [handler, tolua_S](cocos2d::PhysicsWorld &world, cocos2d::PhysicsShape &shape, void * data) -> bool
arg0 = [handler](cocos2d::PhysicsWorld &world, cocos2d::PhysicsShape &shape, void * data) -> bool
{
tolua_pushusertype(tolua_S, (void*)(&world), getLuaTypeName(&world, "cc.PhysicsWorld"));
toluafix_pushusertype_ccobject(tolua_S, shape._ID, &shape._luaID, (void*)(&shape), "cc.PhysicsShape");
return LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2);
auto stack = LuaEngine::getInstance()->getLuaStack();
auto Ls = stack->getLuaState();
tolua_pushusertype(Ls, (void*)(&world), getLuaTypeName(&world, "cc.PhysicsWorld"));
toluafix_pushusertype_ccobject(Ls, shape._ID, &shape._luaID, (void*)(&shape), "cc.PhysicsShape");
return stack->executeFunctionByHandler(handler, 2);
};
} while(0);
@ -298,11 +301,13 @@ int lua_cocos2dx_physics_PhysicsWorld_queryPoint(lua_State* tolua_S)
cocos2d::Vec2 arg1;
LUA_FUNCTION handler = toluafix_ref_function(tolua_S, 2, 0);
do {
arg0 = [handler, tolua_S](cocos2d::PhysicsWorld &world, cocos2d::PhysicsShape &shape, void * data) -> bool
{
tolua_pushusertype(tolua_S, (void*)(&world), getLuaTypeName(&world, "cc.PhysicsWorld"));
toluafix_pushusertype_ccobject(tolua_S, shape._ID, &shape._luaID, (void*)(&shape), "cc.PhysicsShape");
return LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2);
arg0 = [handler](cocos2d::PhysicsWorld &world, cocos2d::PhysicsShape &shape, void * data) -> bool
{
auto stack = LuaEngine::getInstance()->getLuaStack();
auto Ls = stack->getLuaState();
tolua_pushusertype(Ls, (void*)(&world), getLuaTypeName(&world, "cc.PhysicsWorld"));
toluafix_pushusertype_ccobject(Ls, shape._ID, &shape._luaID, (void*)(&shape), "cc.PhysicsShape");
return stack->executeFunctionByHandler(handler, 2);
};
assert(false);
} while(0)

View File

@ -488,8 +488,10 @@ static int lua_cocos2dx_ActionTimeline_setFrameEventCallFunc(lua_State* L)
LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0));
self->setFrameEventCallFunc([=](cocostudio::timeline::Frame* frame){
toluafix_pushusertype_ccobject(L, frame->_ID, &frame->_luaID, (void*)frame, getLuaTypeName(frame, "ccs.Frame"));
LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 1);
auto stack = LuaEngine::getInstance()->getLuaStack();
toluafix_pushusertype_ccobject(stack->getLuaState(), frame->_ID, &frame->_luaID, (void*)frame,
getLuaTypeName(frame, "ccs.Frame"));
stack->executeFunctionByHandler(handler, 1);
});
return 0;

View File

@ -95,11 +95,12 @@ int lua_cocos2dx_csloader_CSLoader_createNode(lua_State* tolua_S)
#endif
LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,3,0));
auto callback = [handler, tolua_S](cocos2d::Ref* ref){
auto callback = [handler](cocos2d::Ref* ref){
if (nullptr == ref)
return;
toluafix_pushusertype_ccobject(tolua_S, ref->_ID, &(ref->_luaID), (void*)ref,"cc.Ref");
LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 1);
auto stack = LuaEngine::getInstance()->getLuaStack();
toluafix_pushusertype_ccobject(stack->getLuaState(), ref->_ID, &(ref->_luaID), (void*)ref, "cc.Ref");
stack->executeFunctionByHandler(handler, 1);
};
cocos2d::Node* ret = cocos2d::CSLoader::createNode(filename, callback);

View File

@ -179,6 +179,9 @@ static int tolua_cocos2dx_EventListenerController_registerScriptHandler(lua_Stat
#endif
LUA_FUNCTION handler = toluafix_ref_function(tolua_S,2,0);
ScriptHandlerMgr::HandlerType type = static_cast<ScriptHandlerMgr::HandlerType>((int)tolua_tonumber(tolua_S, 3, 0));
auto stack = LuaEngine::getInstance()->getLuaStack();
auto Ls = stack->getLuaState();
switch (type)
{
@ -187,11 +190,11 @@ static int tolua_cocos2dx_EventListenerController_registerScriptHandler(lua_Stat
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, type);
self->onConnected = [=](cocos2d::Controller* controller, Event* event){
tolua_pushusertype(tolua_S, (void*)controller, "cc.Controller");
tolua_pushusertype(Ls, (void*)controller, "cc.Controller");
int ID = (event) ? (int)event->_ID : -1;
int* luaID = (event) ? &event->_luaID : NULL;
toluafix_pushusertype_ccobject(tolua_S, ID, luaID, (void*)event,"cc.event");
LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2);
toluafix_pushusertype_ccobject(Ls, ID, luaID, (void*)event, "cc.event");
stack->executeFunctionByHandler(handler, 2);
};
}
break;
@ -200,11 +203,11 @@ static int tolua_cocos2dx_EventListenerController_registerScriptHandler(lua_Stat
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, type);
self->onDisconnected = [=](cocos2d::Controller* controller, Event* event){
tolua_pushusertype(tolua_S, (void*)controller, "cc.Controller");
tolua_pushusertype(Ls, (void*)controller, "cc.Controller");
int ID = (event) ? (int)event->_ID : -1;
int* luaID = (event) ? &event->_luaID : NULL;
toluafix_pushusertype_ccobject(tolua_S, ID, luaID, (void*)event,"cc.event");
LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2);
toluafix_pushusertype_ccobject(Ls, ID, luaID, (void*)event, "cc.event");
stack->executeFunctionByHandler(handler, 2);
};
}
break;
@ -214,12 +217,12 @@ static int tolua_cocos2dx_EventListenerController_registerScriptHandler(lua_Stat
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, type);
self->onKeyDown = [=](cocos2d::Controller* controller, int keyCode, Event* event){
tolua_pushusertype(tolua_S, (void*)controller, "cc.Controller");
tolua_pushnumber(tolua_S, (lua_Number) keyCode);
tolua_pushusertype(Ls, (void*)controller, "cc.Controller");
tolua_pushnumber(Ls, (lua_Number)keyCode);
int ID = (event) ? (int)event->_ID : -1;
int* luaID = (event) ? &event->_luaID : NULL;
toluafix_pushusertype_ccobject(tolua_S, ID, luaID, (void*)event,"cc.event");
LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 3);
toluafix_pushusertype_ccobject(Ls, ID, luaID, (void*)event, "cc.event");
stack->executeFunctionByHandler(handler, 3);
};
}
break;
@ -228,12 +231,12 @@ static int tolua_cocos2dx_EventListenerController_registerScriptHandler(lua_Stat
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, type);
self->onKeyUp = [=](cocos2d::Controller* controller, int keyCode, Event* event){
tolua_pushusertype(tolua_S, (void*)controller, "cc.Controller");
tolua_pushnumber(tolua_S, (lua_Number) keyCode);
tolua_pushusertype(Ls, (void*)controller, "cc.Controller");
tolua_pushnumber(Ls, (lua_Number)keyCode);
int ID = (event) ? (int)event->_ID : -1;
int* luaID = (event) ? &event->_luaID : NULL;
toluafix_pushusertype_ccobject(tolua_S, ID, luaID, (void*)event,"cc.event");
LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 3);
toluafix_pushusertype_ccobject(Ls, ID, luaID, (void*)event, "cc.event");
stack->executeFunctionByHandler(handler, 3);
};
}
break;
@ -242,12 +245,12 @@ static int tolua_cocos2dx_EventListenerController_registerScriptHandler(lua_Stat
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, type);
self->onKeyRepeat = [=](cocos2d::Controller* controller, int keyCode, Event* event){
tolua_pushusertype(tolua_S, (void*)controller, "cc.Controller");
tolua_pushnumber(tolua_S, (lua_Number) keyCode);
tolua_pushusertype(Ls, (void*)controller, "cc.Controller");
tolua_pushnumber(Ls, (lua_Number)keyCode);
int ID = (event) ? (int)event->_ID : -1;
int* luaID = (event) ? &event->_luaID : NULL;
toluafix_pushusertype_ccobject(tolua_S, ID, luaID, (void*)event,"cc.event");
LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 3);
toluafix_pushusertype_ccobject(Ls, ID, luaID, (void*)event, "cc.event");
stack->executeFunctionByHandler(handler, 3);
};
}
break;
@ -256,12 +259,12 @@ static int tolua_cocos2dx_EventListenerController_registerScriptHandler(lua_Stat
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, type);
self->onAxisEvent = [=](cocos2d::Controller* controller, int keyCode, Event* event){
tolua_pushusertype(tolua_S, (void*)controller, "cc.Controller");
tolua_pushnumber(tolua_S, (lua_Number) keyCode);
tolua_pushusertype(Ls, (void*)controller, "cc.Controller");
tolua_pushnumber(Ls, (lua_Number)keyCode);
int ID = (event) ? (int)event->_ID : -1;
int* luaID = (event) ? &event->_luaID : NULL;
toluafix_pushusertype_ccobject(tolua_S, ID, luaID, (void*)event,"cc.event");
LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 3);
toluafix_pushusertype_ccobject(Ls, ID, luaID, (void*)event, "cc.event");
stack->executeFunctionByHandler(handler, 3);
};
}
break;

View File

@ -183,10 +183,11 @@ static int lua_cocos2dx_Extension_EventListenerAssetsManagerEx_create(lua_State*
LUA_FUNCTION handler = toluafix_ref_function(L,3,0);
cocos2d::extension::EventListenerAssetsManagerEx* ret = cocos2d::extension::EventListenerAssetsManagerEx::create(assetManager, [=](EventAssetsManagerEx* event){
auto stack = LuaEngine::getInstance()->getLuaStack();
int id = event? (int)event->_ID : -1;
int* luaID = event? &event->_luaID : nullptr;
toluafix_pushusertype_ccobject(L, id, luaID, (void*)event,"cc.EventAssetsManagerEx");
LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 1);
toluafix_pushusertype_ccobject(stack->getLuaState(), id, luaID, (void*)event, "cc.EventAssetsManagerEx");
stack->executeFunctionByHandler(handler, 1);
});
int id = (ret) ? (int)ret->_ID : -1;

View File

@ -93,9 +93,11 @@ int lua_cocos2dx_navmesh_NavMeshAgent_move(lua_State* tolua_S)
return 0;
}
cobj->move(arg0, [=](cocos2d::NavMeshAgent *agent, float totalTimeAfterMove){
object_to_luaval<cocos2d::NavMeshAgent>(tolua_S, "cc.NavMeshAgent",(cocos2d::NavMeshAgent*)agent);
tolua_pushnumber(tolua_S, (lua_Number)totalTimeAfterMove);
LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2);
auto stack = LuaEngine::getInstance()->getLuaStack();
auto Ls = stack->getLuaState();
object_to_luaval<cocos2d::NavMeshAgent>(Ls, "cc.NavMeshAgent", (cocos2d::NavMeshAgent*)agent);
tolua_pushnumber(Ls, (lua_Number)totalTimeAfterMove);
stack->executeFunctionByHandler(handler, 2);
});
ScriptHandlerMgr::getInstance()->addCustomHandler((void*)cobj, handler);
lua_settop(tolua_S, 1);

View File

@ -730,46 +730,48 @@ int lua_cocos2dx_physics3d_Physics3DObject_setCollisionCallback(lua_State* L)
#endif
LUA_FUNCTION handler = toluafix_ref_function(L,2,0);
cobj->setCollisionCallback([=](const cocos2d::Physics3DCollisionInfo& ci){
lua_newtable(L);
lua_pushstring(L, "objA");
auto stack = LuaEngine::getInstance()->getLuaStack();
auto Ls = stack->getLuaState();
lua_newtable(Ls);
lua_pushstring(Ls, "objA");
if (nullptr == ci.objA)
{
lua_pushnil(L);
lua_pushnil(Ls);
}
else
{
object_to_luaval(L, "cc.Physics3DObject", ci.objA);
object_to_luaval(Ls, "cc.Physics3DObject", ci.objA);
}
lua_rawset(L, -3);
lua_pushstring(L, "objB");
lua_rawset(Ls, -3);
lua_pushstring(Ls, "objB");
if (nullptr == ci.objB)
{
lua_pushnil(L);
lua_pushnil(Ls);
}
else
{
object_to_luaval(L, "cc.Physics3DObject", ci.objB);
object_to_luaval(Ls, "cc.Physics3DObject", ci.objB);
}
lua_rawset(L, -3);
lua_pushstring(L, "collisionPointList");
lua_rawset(Ls, -3);
lua_pushstring(Ls, "collisionPointList");
if (ci.collisionPointList.empty())
{
lua_pushnil(L);
lua_pushnil(Ls);
}
else
{
int vecIndex = 1;
lua_newtable(L);
lua_newtable(Ls);
for (const auto& value : ci.collisionPointList)
{
lua_pushnumber(L, vecIndex);
CollisionPoint_to_luaval(L, value);
lua_rawset(L, -3);
lua_pushnumber(Ls, vecIndex);
CollisionPoint_to_luaval(Ls, value);
lua_rawset(Ls, -3);
++vecIndex;
}
}
lua_rawset(L, -3);
LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 1);
lua_rawset(Ls, -3);
stack->executeFunctionByHandler(handler, 1);
});
ScriptHandlerMgr::getInstance()->addCustomHandler((void*)cobj, handler);

View File

@ -1047,14 +1047,15 @@ static void cloneFocusHandler(const EventListenerFocus* src,EventListenerFocus*
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)dst, newscriptHandler, ScriptHandlerMgr::HandlerType::EVENT_FOCUS);
dst->onFocusChanged = [=](ui::Widget* widgetLostFocus, ui::Widget* widgetGetFocus){
lua_State* L = LuaEngine::getInstance()->getLuaStack()->getLuaState();
auto stack = LuaEngine::getInstance()->getLuaStack();
lua_State* L = stack->getLuaState();
int id = (widgetLostFocus) ? (int)widgetLostFocus->_ID : -1;
int* luaID = (widgetLostFocus) ? &widgetLostFocus->_luaID : nullptr;
toluafix_pushusertype_ccobject(L, id, luaID, (void*)widgetLostFocus,"ccui.Widget");
id = (widgetGetFocus) ? (int)widgetGetFocus->_ID : -1;
luaID = (widgetGetFocus) ? &widgetGetFocus->_luaID : nullptr;
toluafix_pushusertype_ccobject(L, id, luaID, (void*)widgetGetFocus,"ccui.Widget");
LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2);
stack->executeFunctionByHandler(handler, 2);
};
}
}
@ -1141,13 +1142,15 @@ static int tolua_cocos2dx_EventListenerFocus_registerScriptHandler(lua_State* L)
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, ScriptHandlerMgr::HandlerType::EVENT_FOCUS);
self->onFocusChanged = [=](ui::Widget* widgetLostFocus, ui::Widget* widgetGetFocus){
auto stack = LuaEngine::getInstance()->getLuaStack();
auto Ls = stack->getLuaState();
int id = (widgetLostFocus) ? (int)widgetLostFocus->_ID : -1;
int* luaID = (widgetLostFocus) ? &widgetLostFocus->_luaID : nullptr;
toluafix_pushusertype_ccobject(L, id, luaID, (void*)widgetLostFocus,"ccui.Widget");
toluafix_pushusertype_ccobject(Ls, id, luaID, (void*)widgetLostFocus, "ccui.Widget");
id = (widgetGetFocus) ? (int)widgetGetFocus->_ID : -1;
luaID = (widgetGetFocus) ? &widgetGetFocus->_luaID : nullptr;
toluafix_pushusertype_ccobject(L, id, luaID, (void*)widgetGetFocus,"ccui.Widget");
LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2);
toluafix_pushusertype_ccobject(Ls, id, luaID, (void*)widgetGetFocus, "ccui.Widget");
stack->executeFunctionByHandler(handler, 2);
};
return 0;
}