linit.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. ** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $
  3. ** Initialization of libraries for lua.c
  4. ** See Copyright Notice in lua.h
  5. */
  6. #define linit_c
  7. #define LUA_LIB
  8. #define LUAC_CROSS_FILE
  9. #include "lua.h"
  10. #include "lualib.h"
  11. #include "lauxlib.h"
  12. #include "lrotable.h"
  13. #include "luaconf.h"
  14. #include "user_modules.h"
  15. #if defined(LUA_USE_MODULES)
  16. #include "modules.h"
  17. #endif
  18. #if defined(LUA_MODULES_ROM)
  19. #undef _ROM
  20. #define _ROM( name, openf, table ) extern int openf(lua_State *);
  21. LUA_MODULES_ROM
  22. #endif
  23. static const luaL_Reg lualibs[] = {
  24. {"", luaopen_base},
  25. {LUA_LOADLIBNAME, luaopen_package},
  26. #if defined(LUA_USE_BUILTIN_IO)
  27. {LUA_IOLIBNAME, luaopen_io},
  28. #endif
  29. #if defined(LUA_USE_BUILTIN_STRING)
  30. {LUA_STRLIBNAME, luaopen_string},
  31. #endif
  32. #if LUA_OPTIMIZE_MEMORY == 0
  33. #if defined(LUA_USE_BUILTIN_MATH)
  34. {LUA_MATHLIBNAME, luaopen_math},
  35. #endif
  36. #if defined(LUA_USE_BUILTIN_TABLE)
  37. {LUA_TABLIBNAME, luaopen_table},
  38. #endif
  39. #if defined(LUA_USE_BUILTIN_DEBUG) || defined(LUA_USE_BUILTIN_DEBUG_MINIMAL)
  40. {LUA_DBLIBNAME, luaopen_debug},
  41. #endif
  42. #endif
  43. #if defined(LUA_MODULES_ROM)
  44. #undef _ROM
  45. #define _ROM( name, openf, table ) { name, openf },
  46. LUA_MODULES_ROM
  47. #endif
  48. {NULL, NULL}
  49. };
  50. #if defined(LUA_USE_BUILTIN_STRING)
  51. extern const luaR_entry strlib[];
  52. #endif
  53. #if defined(LUA_USE_BUILTIN_OS)
  54. extern const luaR_entry syslib[];
  55. #endif
  56. #if defined(LUA_USE_BUILTIN_TABLE)
  57. extern const luaR_entry tab_funcs[];
  58. #endif
  59. #if defined(LUA_USE_BUILTIN_DEBUG) || defined(LUA_USE_BUILTIN_DEBUG_MINIMAL)
  60. extern const luaR_entry dblib[];
  61. #endif
  62. #if defined(LUA_USE_BUILTIN_COROUTINE)
  63. extern const luaR_entry co_funcs[];
  64. #endif
  65. #if defined(LUA_USE_BUILTIN_MATH)
  66. extern const luaR_entry math_map[];
  67. #endif
  68. #if defined(LUA_MODULES_ROM) && LUA_OPTIMIZE_MEMORY == 2
  69. #undef _ROM
  70. #define _ROM( name, openf, table ) extern const luaR_entry table[];
  71. LUA_MODULES_ROM
  72. #endif
  73. const luaR_table lua_rotable[] =
  74. {
  75. #if LUA_OPTIMIZE_MEMORY > 0
  76. #if defined(LUA_USE_BUILTIN_STRING)
  77. {LUA_STRLIBNAME, strlib},
  78. #endif
  79. #if defined(LUA_USE_BUILTIN_TABLE)
  80. {LUA_TABLIBNAME, tab_funcs},
  81. #endif
  82. #if defined(LUA_USE_BUILTIN_DEBUG) || defined(LUA_USE_BUILTIN_DEBUG_MINIMAL)
  83. {LUA_DBLIBNAME, dblib},
  84. #endif
  85. #if defined(LUA_USE_BUILTIN_COROUTINE)
  86. {LUA_COLIBNAME, co_funcs},
  87. #endif
  88. #if defined(LUA_USE_BUILTIN_MATH)
  89. {LUA_MATHLIBNAME, math_map},
  90. #endif
  91. #if defined(LUA_USE_BUILTIN_OS)
  92. {LUA_OSLIBNAME, syslib},
  93. #endif
  94. #if defined(LUA_MODULES_ROM) && LUA_OPTIMIZE_MEMORY == 2
  95. #undef _ROM
  96. #define _ROM( name, openf, table ) { name, table },
  97. LUA_MODULES_ROM
  98. #endif
  99. #endif
  100. {NULL, NULL}
  101. };
  102. LUALIB_API void luaL_openlibs (lua_State *L) {
  103. const luaL_Reg *lib = lualibs;
  104. for (; lib->func; lib++) {
  105. lua_pushcfunction(L, lib->func);
  106. lua_pushstring(L, lib->name);
  107. lua_call(L, 1, 0);
  108. }
  109. }