1 #include "compat.h"
2
3 #if LUA_VERSION_NUM==501
4 /*
5 ** Adapted from Lua 5.2
6 */
luaL_setfuncs(lua_State * L,const luaL_Reg * l,int nup)7 void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
8 luaL_checkstack(L, nup+1, "too many upvalues");
9 for (; l->name != NULL; l++) { /* fill the table with given functions */
10 int i;
11 lua_pushstring(L, l->name);
12 for (i = 0; i < nup; i++) /* copy upvalues to the top */
13 lua_pushvalue(L, -(nup+1));
14 lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */
15 lua_settable(L, -(nup + 3));
16 }
17 lua_pop(L, nup); /* remove upvalues */
18 }
19
20 /*
21 ** Duplicated from Lua 5.2
22 */
luaL_testudata(lua_State * L,int ud,const char * tname)23 void *luaL_testudata (lua_State *L, int ud, const char *tname) {
24 void *p = lua_touserdata(L, ud);
25 if (p != NULL) { /* value is a userdata? */
26 if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
27 luaL_getmetatable(L, tname); /* get correct metatable */
28 if (!lua_rawequal(L, -1, -2)) /* not the same? */
29 p = NULL; /* value is a userdata with wrong metatable */
30 lua_pop(L, 2); /* remove both metatables */
31 return p;
32 }
33 }
34 return NULL; /* value is not a userdata with a metatable */
35 }
36
37 #endif
38