diff options
| author | Diego Nehab <diego.nehab@gmail.com> | 2015-08-21 15:39:34 -0300 |
|---|---|---|
| committer | Diego Nehab <diego.nehab@gmail.com> | 2015-08-21 15:39:34 -0300 |
| commit | e75444ccd1f30a3b5fbc7cec4a85e831bd0560ed (patch) | |
| tree | 71475c18fee070c770fc0fe25d0859b7d54c8fbb /src/compat.c | |
| parent | 321c0c9b1f7b6b83cd83b58e7e259f53eca69373 (diff) | |
| download | luasocket-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.c | 19 |
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 | */ | ||
| 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 | #endif | ||
