From fb114d8dc6810133ba9e10d75fa9887ee169bf5d Mon Sep 17 00:00:00 2001 From: Philipp Janda Date: Sat, 11 Jul 2015 01:14:47 +0200 Subject: luaL_newmetatable sets __name on all Lua versions. --- c-api/compat-5.3.h | 3 +++ tests/testmod.c | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/c-api/compat-5.3.h b/c-api/compat-5.3.h index cd6764c..e3bbb11 100644 --- a/c-api/compat-5.3.h +++ b/c-api/compat-5.3.h @@ -259,6 +259,9 @@ COMPAT53_API size_t lua_stringtonumber (lua_State *L, const char *s); #define luaL_getmetafield(L, o, e) \ (luaL_getmetafield(L, o, e) ? lua_type(L, -1) : LUA_TNIL) +#define luaL_newmetatable(L, tn) \ + (luaL_newmetatable(L, tn) ? (lua_pushstring(L, tn), lua_setfield(L, -2, "__name"), 1) : 0) + #define luaL_requiref COMPAT53_CONCAT(COMPAT53_PREFIX, L_requiref_53) COMPAT53_API void luaL_requiref (lua_State *L, const char *modname, lua_CFunction openf, int glb ); diff --git a/tests/testmod.c b/tests/testmod.c index c2dc715..2293064 100644 --- a/tests/testmod.c +++ b/tests/testmod.c @@ -205,7 +205,10 @@ static int test_udata (lua_State *L) { (void)u2; lua_pushlightuserdata(L, luaL_testudata(L, u1pos, tname)); lua_pushlightuserdata(L, luaL_testudata(L, u2pos, tname)); - return 2; + luaL_getmetatable(L, "utype1"); + lua_getfield(L, -1, "__name"); + lua_replace(L, -2); + return 3; } static int test_subtable (lua_State *L) { -- cgit v1.2.3-55-g6feb