linit.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. ** $Id: linit.c 2831 2009-12-08 14:19:44Z haraldkipp $
  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/lua.h>
  9. #include <lua/lualib.h>
  10. #include <lua/lauxlib.h>
  11. #include <lua/lrotable.h>
  12. static const luaL_Reg lualibs[] = {
  13. {"", luaopen_base},
  14. #ifdef NUTLUA_LOADLIB_IS_STANDARD
  15. {LUA_LOADLIBNAME, luaopen_package},
  16. #endif
  17. #ifdef NUTLUA_IOLIB_IS_STANDARD
  18. {LUA_IOLIBNAME, luaopen_io},
  19. #endif
  20. #ifdef NUTLUA_STRLIB_IS_STANDARD
  21. {LUA_STRLIBNAME, luaopen_string},
  22. #endif
  23. #if NUTLUA_OPTIMIZE_MEMORY == 0
  24. #ifdef NUTLUA_MATHLIB_IS_STANDARD
  25. {LUA_MATHLIBNAME, luaopen_math},
  26. #endif
  27. #ifdef NUTLUA_OSLIB_IS_STANDARD
  28. {LUA_OSLIBNAME, luaopen_os},
  29. #endif
  30. #ifdef NUTLUA_TABLIB_IS_STANDARD
  31. {LUA_TABLIBNAME, luaopen_table},
  32. #endif
  33. #ifdef NUTLUA_DEBUGLIB_IS_STANDARD
  34. {LUA_DBLIBNAME, luaopen_debug},
  35. #endif
  36. #endif
  37. {NULL, NULL}
  38. };
  39. /* The read-only tables are defined here */
  40. extern const luaL_Reg mathlib[];
  41. extern const luaR_value_entry mathlib_vals[];
  42. extern const luaL_Reg syslib[];
  43. extern const luaL_Reg tab_funcs[];
  44. extern const luaL_Reg dblib[];
  45. extern const luaL_Reg co_funcs[];
  46. const luaR_table lua_rotable[] =
  47. {
  48. #if NUTLUA_OPTIMIZE_MEMORY > 0
  49. #ifndef LAU_MATHLIB_NOT_IMPLEMENTED
  50. {LUA_MATHLIBNAME, mathlib, mathlib_vals},
  51. #endif
  52. #ifndef LAU_OSLIB_NOT_IMPLEMENTED
  53. {LUA_OSLIBNAME, syslib, NULL},
  54. #endif
  55. #ifndef LAU_TABLIB_NOT_IMPLEMENTED
  56. {LUA_TABLIBNAME, tab_funcs, NULL},
  57. #endif
  58. #ifndef LAU_DEBUGLIB_NOT_IMPLEMENTED
  59. {LUA_DBLIBNAME, dblib, NULL},
  60. #endif
  61. {LUA_COLIBNAME, co_funcs, NULL},
  62. #endif
  63. {NULL, NULL, NULL}
  64. };
  65. LUALIB_API void luaL_openlibs (lua_State *L) {
  66. const luaL_Reg *lib = lualibs;
  67. for (; lib->func; lib++) {
  68. lua_pushcfunction(L, lib->func);
  69. lua_pushstring(L, lib->name);
  70. lua_call(L, 1, 0);
  71. }
  72. }