mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-03-21 23:00:03 +01:00
fix interface api in lua5.2
This commit is contained in:
parent
ce58c4aadf
commit
1ceae1ba43
@ -1,11 +1,19 @@
|
||||
#include "LuaCompat.h"
|
||||
|
||||
#if LUA_VERSION_NUM >= 502
|
||||
//implement missing luaL_typerror function
|
||||
// Implement missing luaL_typerror function
|
||||
int luaL_typerror (lua_State *L, int narg, const char *tname)
|
||||
{
|
||||
const char *msg = lua_pushfstring(L, "%s expected, got %s", tname, luaL_typename(L, narg));
|
||||
return luaL_argerror(L, narg, msg);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// Implement function added in lua 5.2 that we now use
|
||||
void lua_pushglobaltable(lua_State *L)
|
||||
{
|
||||
lua_pushvalue(L, LUA_GLOBALSINDEX);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -26,9 +26,10 @@ extern "C"
|
||||
|
||||
#if LUA_VERSION_NUM >= 502
|
||||
#define luaL_getn(L,i) lua_rawlen(L, (i))
|
||||
#define LUA_GLOBALSINDEX LUA_RIDX_GLOBALS
|
||||
|
||||
LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname);
|
||||
#else
|
||||
LUALIB_API void (lua_pushglobaltable) (lua_State *L);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -15,6 +15,9 @@ public:
|
||||
lua_newtable(L);
|
||||
int methods = lua_gettop(L);
|
||||
|
||||
// push global table to the stack, so we can add the component APIs to it
|
||||
lua_pushglobaltable(L);
|
||||
|
||||
luaL_newmetatable(L, T::className);
|
||||
int metatable = lua_gettop(L);
|
||||
|
||||
@ -22,7 +25,7 @@ public:
|
||||
// scripts can add functions written in Lua.
|
||||
lua_pushstring(L, T::className);
|
||||
lua_pushvalue(L, methods);
|
||||
lua_settable(L, LUA_GLOBALSINDEX);
|
||||
lua_settable(L, -4);
|
||||
|
||||
lua_pushliteral(L, "__metatable");
|
||||
lua_pushvalue(L, methods);
|
||||
@ -60,7 +63,7 @@ public:
|
||||
lua_settable(L, methods);
|
||||
}
|
||||
|
||||
lua_pop(L, 2); // drop metatable and method table
|
||||
lua_pop(L, 3); // pop global table, metatable, and method table
|
||||
}
|
||||
|
||||
// get userdata from Lua stack and return pointer to T object
|
||||
|
Loading…
x
Reference in New Issue
Block a user