diff options
Diffstat (limited to 'vendor/luasocket/src/compat.c')
-rw-r--r-- | vendor/luasocket/src/compat.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/vendor/luasocket/src/compat.c b/vendor/luasocket/src/compat.c new file mode 100644 index 00000000..34ffdaf7 --- /dev/null +++ b/vendor/luasocket/src/compat.c | |||
@@ -0,0 +1,39 @@ | |||
1 | #include "luasocket.h" | ||
2 | #include "compat.h" | ||
3 | |||
4 | #if LUA_VERSION_NUM==501 | ||
5 | |||
6 | /* | ||
7 | ** Adapted from Lua 5.2 | ||
8 | */ | ||
9 | void luasocket_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { | ||
10 | luaL_checkstack(L, nup+1, "too many upvalues"); | ||
11 | for (; l->name != NULL; l++) { /* fill the table with given functions */ | ||
12 | int i; | ||
13 | lua_pushstring(L, l->name); | ||
14 | for (i = 0; i < nup; i++) /* copy upvalues to the top */ | ||
15 | lua_pushvalue(L, -(nup+1)); | ||
16 | lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ | ||
17 | lua_settable(L, -(nup + 3)); | ||
18 | } | ||
19 | lua_pop(L, nup); /* remove upvalues */ | ||
20 | } | ||
21 | |||
22 | /* | ||
23 | ** Duplicated from Lua 5.2 | ||
24 | */ | ||
25 | void *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 | |||
39 | #endif | ||