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. #if defined(LUA2RTT_USING_EXLIBS)
  14. #include "lexlibs.h"
  15. #endif
  16. #if defined(LUA_EXLIBS_ROM)
  17. #undef _ROM
  18. #define _ROM( name, openf, table ) extern int openf(lua_State *);
  19. LUA_EXLIBS_ROM;
  20. #endif
  21. static const luaL_Reg lualibs[] =
  22. {
  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. {LUA_OSLIBNAME , luaopen_os },
  32. #endif
  33. #if defined(LUA_EXLIBS_ROM)
  34. #undef _ROM
  35. #define _ROM(name, openf, table) {name, openf},
  36. LUA_EXLIBS_ROM
  37. #endif
  38. {NULL, NULL}
  39. };
  40. extern const luaR_entry strlib[];
  41. extern const luaR_entry syslib[];
  42. extern const luaR_entry tab_funcs[];
  43. extern const luaR_entry dblib[];
  44. extern const luaR_entry co_funcs[];
  45. #if defined(LUA_EXLIBS_ROM) && LUA_OPTIMIZE_MEMORY == 2
  46. #undef _ROM
  47. #define _ROM( name, openf, table ) extern const luaR_entry table[];
  48. LUA_EXLIBS_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. #if defined(LUA_EXLIBS_ROM) && LUA_OPTIMIZE_MEMORY == 2
  58. #undef _ROM
  59. #define _ROM( name, openf, table ) { name, table },
  60. LUA_EXLIBS_ROM
  61. #endif
  62. #endif
  63. {NULL, NULL}
  64. };
  65. LUALIB_API void luaL_openlibs(lua_State *L)
  66. {
  67. const luaL_Reg *lib = lualibs;
  68. for (; lib->func; lib++)
  69. {
  70. lua_pushcfunction(L, lib->func);
  71. lua_pushstring(L, lib->name);
  72. lua_call(L, 1, 0);
  73. }
  74. }