6

In the code example: http://lua-users.org/wiki/SimplerCppBinding

There is the code:

lua_pushstring(L, T::className);
lua_pushvalue(L, methods);
lua_settable(L, LUA_GLOBALSINDEX);  //<--- LUA_GLOBALSINDEX removed in Lua 5.2

lua_pushliteral(L, "__metatable");
lua_pushvalue(L, methods);
lua_settable(L, metatable); 

In Lua 5.2, LUA_GLOBALSINDEX no longer exists. Instead, it has lua_setglobal() and lua_getglobal().


Am I correct in thinking that:

lua_pushvalue(L, methods);
lua_setglobal(L, T::className);

...is the correct replacement for:

lua_pushstring(L, T::className);
lua_pushvalue(L, methods);
lua_settable(L, LUA_GLOBALSINDEX);

I'm too new to Lua to be sure, I haven't used it for 8 months. Looking at the documentation, I'm thinking this is correct, but would like verification.

4

1 回答 1

5

而不是lua_settable(L,LUA_GLOBALSINDEX);使用lua_setglobal(L,T::className);. 这适用于 Lua 5.1 和 5.2。

于 2012-01-30T10:23:55.623 回答