zoukankan      html  css  js  c++  java
  • 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 
    ", "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;
    }

    编译运行,回调生效啦

  • 相关阅读:
    【 D3.js 选择集与数据详解 — 5 】 处理模板的应用
    阿里云至 Windows Azure 的 Linux 虚拟机迁移
    【 随笔 】 JavaScript 图形库的流行度调查
    2015年,新的启程
    【 D3.js 选择集与数据详解 — 4 】 enter和exit的处理方法以及处理模板
    【 随笔 】 财源滚滚
    HelloXV1.77网络功能简介
    【 D3.js 选择集与数据详解 — 3 】 绑定数据的顺序
    【 D3.js 选择集与数据详解 — 2 】 使用data()绑定数据
    保持与 Microsoft Azure Files 的连接
  • 原文地址:https://www.cnblogs.com/whj0402/p/12205403.html
Copyright © 2011-2022 走看看