aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Nehab <diego.nehab@gmail.com>2018-06-05 10:54:55 -0300
committerGitHub <noreply@github.com>2018-06-05 10:54:55 -0300
commit4df569e9f867432f25f0bfbfa56b0962feb3326e (patch)
tree8d3be51d975a78ea7174cc15b4fa85390be70b84
parentcc42bcbf80c8184d64d9fe28ef8d18472f49ba76 (diff)
parent5848de4851619a757951f3ef041c1e71691b6a97 (diff)
downloadluasocket-4df569e9f867432f25f0bfbfa56b0962feb3326e.tar.gz
luasocket-4df569e9f867432f25f0bfbfa56b0962feb3326e.tar.bz2
luasocket-4df569e9f867432f25f0bfbfa56b0962feb3326e.zip
Merge pull request #250 from ewestbrook/testudata-compat
Update auxiliar.c to use luaL_testudata (#249), now with Lua 5.1 compatibility
-rw-r--r--src/auxiliar.c2
-rw-r--r--src/compat.c18
-rw-r--r--src/compat.h1
3 files changed, 20 insertions, 1 deletions
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) {
143* otherwise 143* otherwise
144\*-------------------------------------------------------------------------*/ 144\*-------------------------------------------------------------------------*/
145void *auxiliar_getclassudata(lua_State *L, const char *classname, int objidx) { 145void *auxiliar_getclassudata(lua_State *L, const char *classname, int objidx) {
146 return luaL_checkudata(L, objidx, classname); 146 return luaL_testudata(L, objidx, classname);
147} 147}
148 148
149/*-------------------------------------------------------------------------*\ 149/*-------------------------------------------------------------------------*\
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*/
23void *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
8void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup); 8void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup);
9void *luaL_testudata ( lua_State *L, int arg, const char *tname);
9#endif 10#endif
10 11
11#endif 12#endif