From be3c6d67e0e89a52a91a95c46f402e3b5d42a6c5 Mon Sep 17 00:00:00 2001 From: Bruno Silvestre Date: Sat, 28 Oct 2017 09:53:28 -0200 Subject: [PATCH] Make luaL_testudata() compat function visible for all files --- src/compat.h | 2 ++ src/context.c | 41 +++++++++++++++++++---------------------- src/context.h | 5 +++++ 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/compat.h b/src/compat.h index 0fabead..be0b0fc 100644 --- a/src/compat.h +++ b/src/compat.h @@ -16,8 +16,10 @@ #if (LUA_VERSION_NUM == 501) +#define luaL_testudata(L, ud, tname) lsec_testudata(L, ud, tname) #define setfuncs(L, R) luaL_register(L, NULL, R) #define lua_rawlen(L, i) lua_objlen(L, i) + #ifndef luaL_newlib #define luaL_newlib(L, R) do { lua_newtable(L); luaL_register(L, NULL, R); } while(0) #endif diff --git a/src/context.c b/src/context.c index 18de6af..8455901 100644 --- a/src/context.c +++ b/src/context.c @@ -35,28 +35,6 @@ typedef const SSL_METHOD LSEC_SSL_METHOD; typedef SSL_METHOD LSEC_SSL_METHOD; #endif -/*-- Compat - Lua 5.1 --------------------------------------------------------*/ - -#if (LUA_VERSION_NUM == 501) - -#define luaL_testudata(L, ud, tname) testudata(L, ud, tname) - -static void *testudata (lua_State *L, int ud, const char *tname) { - void *p = lua_touserdata(L, ud); - if (p != NULL) { /* value is a userdata? */ - if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ - luaL_getmetatable(L, tname); /* get correct metatable */ - if (!lua_rawequal(L, -1, -2)) /* not the same? */ - p = NULL; /* value is a userdata with wrong metatable */ - lua_pop(L, 2); /* remove both metatables */ - return p; - } - } - return NULL; /* value is not a userdata with a metatable */ -} - -#endif - /*--------------------------- Auxiliary Functions ----------------------------*/ /** @@ -773,6 +751,25 @@ int lsec_getmode(lua_State *L, int idx) return ctx->mode; } +/*-- Compat - Lua 5.1 --*/ +#if (LUA_VERSION_NUM == 501) + +void *lsec_testudata (lua_State *L, int ud, const char *tname) { + void *p = lua_touserdata(L, ud); + if (p != NULL) { /* value is a userdata? */ + if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ + luaL_getmetatable(L, tname); /* get correct metatable */ + if (!lua_rawequal(L, -1, -2)) /* not the same? */ + p = NULL; /* value is a userdata with wrong metatable */ + lua_pop(L, 2); /* remove both metatables */ + return p; + } + } + return NULL; /* value is not a userdata with a metatable */ +} + +#endif + /*------------------------------ Initialization ------------------------------*/ /** diff --git a/src/context.h b/src/context.h index f926f6b..a971550 100644 --- a/src/context.h +++ b/src/context.h @@ -38,4 +38,9 @@ int lsec_getmode(lua_State *L, int idx); /* Registre the module. */ LSEC_API int luaopen_ssl_context(lua_State *L); +/* Compat - Lua 5.1 */ +#if (LUA_VERSION_NUM == 501) +void *lsec_testudata (lua_State *L, int ud, const char *tname); +#endif + #endif