diff options
author | Caleb Maclennan <caleb@alerque.com> | 2023-11-10 09:12:04 +0300 |
---|---|---|
committer | Caleb Maclennan <caleb@alerque.com> | 2023-11-10 09:12:04 +0300 |
commit | 5c4fc93d5f4137bf4c22ddf1a048c907a4a26727 (patch) | |
tree | a9a68e1f6a9c3bfe2b64fa1c3a4098865b7d3b5d /src/compat.c | |
parent | ccef3bc4e2aa6ee5b997a80aabb58f4ff0b0e98f (diff) | |
parent | 43a97b7f0053313b43906371dbdc226271e6c8ab (diff) | |
download | luasocket-hjelmeland-patch-1.tar.gz luasocket-hjelmeland-patch-1.tar.bz2 luasocket-hjelmeland-patch-1.zip |
Merge branch 'master' into hjelmeland-patch-1hjelmeland-patch-1
Diffstat (limited to '')
-rw-r--r-- | src/compat.c | 22 |
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 | */ |
7 | void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { | 9 | void 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 | */ | ||
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 | |||
19 | #endif | 39 | #endif |