cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.22k stars 7.05k forks source link

all callback export to lua is not support bind in coroutine #18045

Open owen200008 opened 7 years ago

owen200008 commented 7 years ago

all callback export to lua is not support bind in coroutine。 like following:

now is wrong:

        cocos2d::extension::EventListenerAssetsManagerEx* ret = cocos2d::extension::EventListenerAssetsManagerEx::create(assetManager, [=](EventAssetsManagerEx* event){
            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);
        });

correct:

cocos2d::extension::EventListenerAssetsManagerEx* ret = cocos2d::extension::EventListenerAssetsManagerEx::create(assetManager, [=](EventAssetsManagerEx* event){
            int id = event? (int)event->_ID : -1;
            int* luaID = event? &event->_luaID : nullptr;
            toluafix_pushusertype_ccobject(LuaEngine::getInstance()->getLuaStack()->getLuaState(), id, luaID, (void*)event,"cc.EventAssetsManagerEx");
            LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 1);
        });
minggo commented 7 years ago

Sorry, i am not familiar with lua coroutine. Could you please describe it in more detail? Does it break compatibility?

owen200008 commented 7 years ago

it mustbe no break compatibility。 every coroutine have own luastate,main thread is same。 all the cocos callback is in c++ ui thread, so it mean's all the lua coroutine is suspend. it is wait the lua main thread to wakeup. now the code callback with coroutine luastate, but this coroutine is suspend. so we must callback in the lua main thread.