linit.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #include "lua.h"
  9. #include "lualib.h"
  10. #include "lauxlib.h"
  11. #include "lrotable.h"
  12. #include "luaconf.h"
  13. #include "user_modules.h"
  14. #if defined(LUA_USE_MODULES)
  15. #include "modules.h"
  16. #endif
  17. #if defined(LUA_MODULES_ROM)
  18. #undef _ROM
  19. #define _ROM( name, openf, table ) extern int openf(lua_State *);
  20. LUA_MODULES_ROM
  21. #endif
  22. static const luaL_Reg lualibs[] = {
  23. {"", luaopen_base},
  24. {LUA_LOADLIBNAME, luaopen_package},
  25. // {LUA_IOLIBNAME, luaopen_io},
  26. {LUA_STRLIBNAME, luaopen_string},
  27. #if LUA_OPTIMIZE_MEMORY == 0
  28. // {LUA_MATHLIBNAME, luaopen_math},
  29. {LUA_TABLIBNAME, luaopen_table},
  30. // {LUA_DBLIBNAME, luaopen_debug},
  31. #endif
  32. #if defined(LUA_MODULES_ROM)
  33. #undef _ROM
  34. #define _ROM( name, openf, table ) { name, openf },
  35. LUA_MODULES_ROM
  36. #endif
  37. {NULL, NULL}
  38. };
  39. extern const luaR_entry strlib[];
  40. extern const luaR_entry syslib[];
  41. extern const luaR_entry tab_funcs[];
  42. // extern const luaR_entry dblib[];
  43. extern const luaR_entry co_funcs[];
  44. // extern const luaR_entry math_map[];
  45. #if defined(LUA_MODULES_ROM) && LUA_OPTIMIZE_MEMORY == 2
  46. #undef _ROM
  47. #define _ROM( name, openf, table ) extern const luaR_entry table[];
  48. LUA_MODULES_ROM
  49. #endif
  50. const luaR_table lua_rotable[] =
  51. {
  52. #if LUA_OPTIMIZE_MEMORY > 0
  53. {LUA_STRLIBNAME, strlib},
  54. {LUA_TABLIBNAME, tab_funcs},
  55. // {LUA_DBLIBNAME, dblib},
  56. {LUA_COLIBNAME, co_funcs},
  57. // {LUA_MATHLIBNAME, math_map},
  58. #if defined(LUA_MODULES_ROM) && LUA_OPTIMIZE_MEMORY == 2
  59. #undef _ROM
  60. #define _ROM( name, openf, table ) { name, table },
  61. LUA_MODULES_ROM
  62. #endif
  63. #endif
  64. {NULL, NULL}
  65. };
  66. LUALIB_API void luaL_openlibs (lua_State *L) {
  67. const luaL_Reg *lib = lualibs;
  68. for (; lib->func; lib++) {
  69. lua_pushcfunction(L, lib->func);
  70. lua_pushstring(L, lib->name);
  71. lua_call(L, 1, 0);
  72. }
  73. }