summaryrefslogtreecommitdiff
path: root/src/compat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/compat.c')
-rw-r--r--src/compat.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/compat.c b/src/compat.c
index 6f98854..2d2bec9 100644
--- a/src/compat.c
+++ b/src/compat.c
@@ -14,4 +14,20 @@ void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup) {
}
lua_pop(L, nup); /* remove upvalues */
}
+
+void *luaL_testudata(lua_State *L, int ud, const char *tname) {
+ void *p = lua_touserdata(L, ud);
+ if (p != NULL) { /* Check for userdata */
+ if (lua_getmetatable(L, ud)) { /* Does it have a metatable? */
+ lua_getfield(L, LUA_REGISTRYINDEX, tname); /* Get metatable we're looking for */
+ if (lua_rawequal(L, -1, -2)) { /* Compare metatables */
+ lua_pop(L, 2); /* Remove metatables from stack */
+ return p;
+ }
+ lua_pop(L, 2); /* Remove metatables from stack */
+ }
+ }
+ return NULL; /* Return NULL if check fails */
+}
+
#endif