mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-26 04:28:20 +01:00
src/compat.c: provide luaL_testudata() for use by auxiliar.c under Lua 5.1
This commit is contained in:
parent
e1e41be948
commit
5848de4851
18
src/compat.c
18
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 */
|
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
|
#endif
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#if LUA_VERSION_NUM==501
|
#if LUA_VERSION_NUM==501
|
||||||
void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup);
|
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
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user