From e1e41be948196a98af67345d51fe7a238c850c54 Mon Sep 17 00:00:00 2001 From: George Zhao Date: Sun, 3 Jun 2018 20:08:02 +0800 Subject: [PATCH 1/2] Update auxiliar.c --- src/auxiliar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/auxiliar.c b/src/auxiliar.c index 18fa8e4..5251549 100644 --- a/src/auxiliar.c +++ b/src/auxiliar.c @@ -143,7 +143,7 @@ void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx) { * otherwise \*-------------------------------------------------------------------------*/ void *auxiliar_getclassudata(lua_State *L, const char *classname, int objidx) { - return luaL_checkudata(L, objidx, classname); + return luaL_testudata(L, objidx, classname); } /*-------------------------------------------------------------------------*\ From 5848de4851619a757951f3ef041c1e71691b6a97 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 4 Jun 2018 20:14:13 -0600 Subject: [PATCH 2/2] src/compat.c: provide luaL_testudata() for use by auxiliar.c under Lua 5.1 --- src/compat.c | 18 ++++++++++++++++++ src/compat.h | 1 + 2 files changed, 19 insertions(+) diff --git a/src/compat.c b/src/compat.c index c2d99cb..988fa68 100644 --- a/src/compat.c +++ b/src/compat.c @@ -16,4 +16,22 @@ void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { } lua_pop(L, nup); /* remove upvalues */ } + +/* +** Duplicated from Lua 5.2 +*/ +void *luaL_testudata (lua_State *L, int ud, const char *tname) { + void *p = lua_touserdata(L, ud); + if (p != NULL) { /* value is a userdata? */ + if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ + luaL_getmetatable(L, tname); /* get correct metatable */ + if (!lua_rawequal(L, -1, -2)) /* not the same? */ + p = NULL; /* value is a userdata with wrong metatable */ + lua_pop(L, 2); /* remove both metatables */ + return p; + } + } + return NULL; /* value is not a userdata with a metatable */ +} + #endif diff --git a/src/compat.h b/src/compat.h index 7bf8010..e2ab307 100644 --- a/src/compat.h +++ b/src/compat.h @@ -6,6 +6,7 @@ #if LUA_VERSION_NUM==501 void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup); +void *luaL_testudata ( lua_State *L, int arg, const char *tname); #endif #endif