compat-5.2.c 706 B

12345678910111213141516171819202122
  1. #include "lua.h"
  2. #include "lauxlib.h"
  3. #include "compat-5.2.h"
  4. #if !defined LUA_VERSION_NUM || LUA_VERSION_NUM==501
  5. /*
  6. ** Adapted from Lua 5.2.0
  7. */
  8. void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
  9. luaL_checkstack(L, nup+1, "too many upvalues");
  10. for (; l->name != NULL; l++) { /* fill the table with given functions */
  11. int i;
  12. lua_pushstring(L, l->name);
  13. for (i = 0; i < nup; i++) /* copy upvalues to the top */
  14. lua_pushvalue(L, -(nup + 1));
  15. lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */
  16. lua_settable(L, -(nup + 3)); /* table must be below the upvalues, the name and the closure */
  17. }
  18. lua_pop(L, nup); /* remove upvalues */
  19. }
  20. #endif