Permalink
Browse files

fix interface api in lua5.2

  • Loading branch information...
jacob1 committed Aug 20, 2017
1 parent ce58c4a commit 1ceae1ba43dd568172e4ae4c5e6aebf82e8f048a
Showing with 16 additions and 4 deletions.
  1. +9 −1 src/lua/LuaCompat.c
  2. +2 −1 src/lua/LuaCompat.h
  3. +5 −2 src/lua/LuaLuna.h
@@ -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,14 +15,17 @@ template <typename T> class Luna
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);
// store method table in globals so that
// 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 @@ template <typename T> class Luna
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

0 comments on commit 1ceae1b

Please sign in to comment.