diff options
author | E. Westbrook <github@westbrook.io> | 2018-06-04 20:14:13 -0600 |
---|---|---|
committer | E. Westbrook <github@westbrook.io> | 2018-06-04 20:14:13 -0600 |
commit | 5848de4851619a757951f3ef041c1e71691b6a97 (patch) | |
tree | 9b55b4117cfeece787f6c64817e1bdd7bd223341 | |
parent | e1e41be948196a98af67345d51fe7a238c850c54 (diff) | |
download | luasocket-5848de4851619a757951f3ef041c1e71691b6a97.tar.gz luasocket-5848de4851619a757951f3ef041c1e71691b6a97.tar.bz2 luasocket-5848de4851619a757951f3ef041c1e71691b6a97.zip |
src/compat.c: provide luaL_testudata() for use by auxiliar.c under Lua 5.1
-rw-r--r-- | src/compat.c | 18 | ||||
-rw-r--r-- | src/compat.h | 1 |
2 files changed, 19 insertions, 0 deletions
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) { | |||
16 | } | 16 | } |
17 | lua_pop(L, nup); /* remove upvalues */ | 17 | lua_pop(L, nup); /* remove upvalues */ |
18 | } | 18 | } |
19 | |||
20 | /* | ||
21 | ** Duplicated from Lua 5.2 | ||
22 | */ | ||
23 | void *luaL_testudata (lua_State *L, int ud, const char *tname) { | ||
24 | void *p = lua_touserdata(L, ud); | ||
25 | if (p != NULL) { /* value is a userdata? */ | ||
26 | if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ | ||
27 | luaL_getmetatable(L, tname); /* get correct metatable */ | ||
28 | if (!lua_rawequal(L, -1, -2)) /* not the same? */ | ||
29 | p = NULL; /* value is a userdata with wrong metatable */ | ||
30 | lua_pop(L, 2); /* remove both metatables */ | ||
31 | return p; | ||
32 | } | ||
33 | } | ||
34 | return NULL; /* value is not a userdata with a metatable */ | ||
35 | } | ||
36 | |||
19 | #endif | 37 | #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 @@ | |||
6 | 6 | ||
7 | #if LUA_VERSION_NUM==501 | 7 | #if LUA_VERSION_NUM==501 |
8 | void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup); | 8 | void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup); |
9 | void *luaL_testudata ( lua_State *L, int arg, const char *tname); | ||
9 | #endif | 10 | #endif |
10 | 11 | ||
11 | #endif | 12 | #endif |