aboutsummaryrefslogtreecommitdiff
path: root/src/compat.c
diff options
context:
space:
mode:
authorDiego Nehab <diego.nehab@gmail.com>2015-08-21 15:39:34 -0300
committerDiego Nehab <diego.nehab@gmail.com>2015-08-21 15:39:34 -0300
commite75444ccd1f30a3b5fbc7cec4a85e831bd0560ed (patch)
tree71475c18fee070c770fc0fe25d0859b7d54c8fbb /src/compat.c
parent321c0c9b1f7b6b83cd83b58e7e259f53eca69373 (diff)
downloadluasocket-e75444ccd1f30a3b5fbc7cec4a85e831bd0560ed.tar.gz
luasocket-e75444ccd1f30a3b5fbc7cec4a85e831bd0560ed.tar.bz2
luasocket-e75444ccd1f30a3b5fbc7cec4a85e831bd0560ed.zip
New compat.h module implements luaL_setfuncs.
Makes initialization code simpler everywhere.
Diffstat (limited to 'src/compat.c')
-rw-r--r--src/compat.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/compat.c b/src/compat.c
new file mode 100644
index 0000000..bc5cc0e
--- /dev/null
+++ b/src/compat.c
@@ -0,0 +1,19 @@
1#include "compat.h"
2
3#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM==501
4/*
5** Adapted from Lua 5.2
6*/
7void 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#endif