linit.c 969 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. ** $Id: linit.c,v 1.9 2005/02/18 12:40:02 roberto Exp roberto $
  3. ** Initialization of libraries for lua.c
  4. ** See Copyright Notice in lua.h
  5. */
  6. #define linit_c
  7. #define LUA_LIB
  8. #include "lua.h"
  9. #include "lualib.h"
  10. #include "lauxlib.h"
  11. static const luaL_reg lualibs[] = {
  12. {"", luaopen_base},
  13. {LUA_TABLIBNAME, luaopen_table},
  14. {LUA_IOLIBNAME, luaopen_io},
  15. {LUA_OSLIBNAME, luaopen_os},
  16. {LUA_STRLIBNAME, luaopen_string},
  17. {LUA_MATHLIBNAME, luaopen_math},
  18. {LUA_DBLIBNAME, luaopen_debug},
  19. {"", luaopen_loadlib},
  20. {NULL, NULL}
  21. };
  22. LUALIB_API int luaopen_stdlibs (lua_State *L) {
  23. const luaL_reg *lib = lualibs;
  24. int t = lua_gettop(L);
  25. lua_pushvalue(L, LUA_ENVIRONINDEX); /* save original environment */
  26. for (; lib->func; lib++) {
  27. lib->func(L); /* open library */
  28. lua_settop(L, t + 1); /* discard any results */
  29. lua_pushvalue(L, -1);
  30. lua_replace(L, LUA_ENVIRONINDEX); /* restore environment */
  31. }
  32. lua_pop(L, 1);
  33. return 0;
  34. }