Skip to content

Commit fb114d8

Browse files
committed
luaL_newmetatable sets __name on all Lua versions.
1 parent 823345b commit fb114d8

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

c-api/compat-5.3.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ COMPAT53_API size_t lua_stringtonumber (lua_State *L, const char *s);
259259
#define luaL_getmetafield(L, o, e) \
260260
(luaL_getmetafield(L, o, e) ? lua_type(L, -1) : LUA_TNIL)
261261

262+
#define luaL_newmetatable(L, tn) \
263+
(luaL_newmetatable(L, tn) ? (lua_pushstring(L, tn), lua_setfield(L, -2, "__name"), 1) : 0)
264+
262265
#define luaL_requiref COMPAT53_CONCAT(COMPAT53_PREFIX, L_requiref_53)
263266
COMPAT53_API void luaL_requiref (lua_State *L, const char *modname,
264267
lua_CFunction openf, int glb );

tests/testmod.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,10 @@ static int test_udata (lua_State *L) {
205205
(void)u2;
206206
lua_pushlightuserdata(L, luaL_testudata(L, u1pos, tname));
207207
lua_pushlightuserdata(L, luaL_testudata(L, u2pos, tname));
208-
return 2;
208+
luaL_getmetatable(L, "utype1");
209+
lua_getfield(L, -1, "__name");
210+
lua_replace(L, -2);
211+
return 3;
209212
}
210213

211214
static int test_subtable (lua_State *L) {

0 commit comments

Comments
 (0)