compat.c 567 B

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