在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
C 调用 lua 函数 需要考虑的问题: int LuaTest::Attach(lua_State* luaState) { if(lua_isfunction(luaState, 1) != 1) { return 0; } lua_settop(luaState, 1); m_nRef = luaL_ref(luaState, LUA_REGISTRYINDEX); // 保存到 LUA_REGISTRYINDEX 表 lua_pushinteger(luaState, nRef); return 1; } int LuaTest::Detach(lua_State* luaState) { m_nRef = luaL_checknumber(luaState, 1); luaL_unref(luaState, LUA_REGISTRYINDEX, nRef); // 从 LUA_REGISTRYINDEX 表中删除 m_nRef = 0; return 0; } // 事件监听函数 void LuaTest::EventListener(lua_State* luaState) { lua_rawgeti(luaState, LUA_REGISTRYINDEX, m_nRef); // 从 LUA_REGISTRYINDEX 表中获取 lua_pushstring(luaState, "参数1"); lua_pushstring(luaState, "参数2"); lua_pcall(luaState, 2, 1, 0); // 调用 lua 函数 int nRet = luaL_checknumber(luaState, -1); // 返回值 }
参考文章: http://blog.csdn.net/ani_di/article/details/10590587 |
请发表评论