From 10744ada73badac1762b5f2b388b3215f61b8727 Mon Sep 17 00:00:00 2001 From: Tomas Guisasola Date: Fri, 16 Aug 2013 19:46:51 -0300 Subject: [PATCH] Defining luaL_newmetatable() for Lua 5.0 code. --- src/luasql.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/luasql.c b/src/luasql.c index b518c74..abadd9f 100644 --- a/src/luasql.c +++ b/src/luasql.c @@ -80,6 +80,23 @@ void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { } #endif +#if !defined(LUA_VERSION_NUM) +/* +** Adapted from Lua 5.2.0 +*/ +LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) { + luaL_getmetatable(L, tname); /* try to get metatable */ + if (!lua_isnil(L, -1)) /* name already in use? */ + return 0; /* leave previous value on top, but return 0 */ + lua_pop(L, 1); + lua_newtable(L); /* create metatable */ + lua_pushstring(L, tname); + lua_pushvalue(L, -1); + lua_settable(L, LUA_REGISTRYINDEX); + return 1; +} +#endif + /* ** Create a metatable and leave it on top of the stack. */