Cocos2dLua3.17.2集成FairyGUI之 lua绑定 setHook()回调问题(四)

在使用fairyGUI的时候,发现在使用setHook()设置回调的时候,没有效果,于是又去翻看源码。原来Lambda binding for lua is not supported.无法导出功能。只能手动修改了

找到lua_cocos2dx_fairygui_auto.cpp文件,找到lua_cocos2dx_fairygui_Transition_setHook函数,注释掉里面无法导出的while循环。

  //      do {
        //    // Lambda binding for lua is not supported.
        //    assert(false);
        //} while(0)
        //;

写入功能函数,整个函数修改如下

int lua_cocos2dx_fairygui_Transition_setHook(lua_State* tolua_S)
{
    int argc = 0;
    fairygui::Transition* cobj = nullptr;
    bool ok  = true;

#if COCOS2D_DEBUG >= 1
    tolua_Error tolua_err;
#endif


#if COCOS2D_DEBUG >= 1
    if (!tolua_isusertype(tolua_S,1,"fgui.Transition",0,&tolua_err)) goto tolua_lerror;
#endif

    cobj = (fairygui::Transition*)tolua_tousertype(tolua_S,1,0);

#if COCOS2D_DEBUG >= 1
    if (!cobj) 
    {
        tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_fairygui_Transition_setHook'", nullptr);
        return 0;
    }
#endif

    argc = lua_gettop(tolua_S)-1;
    if (argc == 2) 
    {
        std::string arg0;
        std::function<void ()> arg1;

        ok &= luaval_to_std_string(tolua_S, 2,&arg0, "fgui.Transition:setHook");

  //      do {
        //    // Lambda binding for lua is not supported.
        //    assert(false);
        //} while(0)
        //;

        LUA_FUNCTION handler = (toluafix_ref_function(tolua_S, 3, 0));
        cobj->setHook(arg0, [=]() {  

        LuaStack* stack = LuaEngine::getInstance()->getLuaStack();
        stack->executeFunctionByHandler(handler, 0);
        stack->clean();

        });
        if(!ok)
        {
            tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_fairygui_Transition_setHook'", nullptr);
            return 0;
        }
        
        //cobj->setHook(arg0, arg1);
        lua_settop(tolua_S, 1);
        return 1;
    }
    luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "fgui.Transition:setHook",argc, 2);
    return 0;

#if COCOS2D_DEBUG >= 1
    tolua_lerror:
    tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_fairygui_Transition_setHook'.",&tolua_err);
#endif

    return 0;
}

编译运行,回调生效啦

 

上一篇:centos 编译lua


下一篇:17.3 项目:添加徽标