5
私はLuaを初めて使っています。 私はC++からLua関数を呼び出す方法のサンプルコードを見てきましたが、サンプルコードでは5.1が使用されていますが、これを5.2で動作させようとしています。ここでC++からLua 5.2関数を呼び出す
は、私のコメントと質問のサンプルコードです:
lua_State *luaState = luaL_newstate();
luaopen_io(luaState);
luaL_loadfile(luaState, "myLuaScript.lua");
lua_pcall(luaState, 0, LUA_MULTRET, 0);
//the code below needs to be rewritten i suppose
lua_pushstring(luaState, "myLuaFunction");
//the line of code below does not work in 5.2
lua_gettable(luaState, LUA_GLOBALSINDEX);
lua_pcall(luaState, 0, 0, 0);
私は1つは、レジストリ(代わりのlua_gettableから地球環境を取得する必要があると5.2参照マヌエル(http://www.lua.org/manual/5.2/manual.html#8.3)で読みました上記のステートメント)しかし、私はこの作業をするために必要な変更を解決することはできません。私は試したことがあります:
lua_pushglobaltable(luaState);
lua_pushstring(luaState, "myLuaFunction");
lua_gettable(luaState, -2);
lua_pcall(luaState, 0, 0, 0);
も参照してください。http://stackoverflow.com/questions/11093189/lua-updating-from-5-1-lua-globalsindex-problems – lhf