aboutsummaryrefslogtreecommitdiff
path: root/src/compat.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/compat.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/compat.c b/src/compat.c
index c2d99cb..34ffdaf 100644
--- a/src/compat.c
+++ b/src/compat.c
@@ -1,10 +1,12 @@
1#include "luasocket.h"
1#include "compat.h" 2#include "compat.h"
2 3
3#if LUA_VERSION_NUM==501 4#if LUA_VERSION_NUM==501
5
4/* 6/*
5** Adapted from Lua 5.2 7** Adapted from Lua 5.2
6*/ 8*/
7void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { 9void luasocket_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
8 luaL_checkstack(L, nup+1, "too many upvalues"); 10 luaL_checkstack(L, nup+1, "too many upvalues");
9 for (; l->name != NULL; l++) { /* fill the table with given functions */ 11 for (; l->name != NULL; l++) { /* fill the table with given functions */
10 int i; 12 int i;
@@ -16,4 +18,22 @@ void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
16 } 18 }
17 lua_pop(L, nup); /* remove upvalues */ 19 lua_pop(L, nup); /* remove upvalues */
18} 20}
21
22/*
23** Duplicated from Lua 5.2
24*/
25void *luasocket_testudata (lua_State *L, int ud, const char *tname) {
26 void *p = lua_touserdata(L, ud);
27 if (p != NULL) { /* value is a userdata? */
28 if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
29 luaL_getmetatable(L, tname); /* get correct metatable */
30 if (!lua_rawequal(L, -1, -2)) /* not the same? */
31 p = NULL; /* value is a userdata with wrong metatable */
32 lua_pop(L, 2); /* remove both metatables */
33 return p;
34 }
35 }
36 return NULL; /* value is not a userdata with a metatable */
37}
38
19#endif 39#endif