mirror of
https://github.com/brunoos/luasec.git
synced 2025-07-13 06:24:22 +02:00
Make luaL_testudata() compat function visible for all files
This commit is contained in:
@ -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 ------------------------------*/
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user