linit.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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(RT_LUA_USE_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. {"", luaopen_base},
  23. {LUA_LOADLIBNAME, luaopen_package},
  24. {LUA_IOLIBNAME, luaopen_io},
  25. {LUA_STRLIBNAME, luaopen_string},
  26. #if LUA_OPTIMIZE_MEMORY == 0
  27. {LUA_MATHLIBNAME, luaopen_math},
  28. {LUA_TABLIBNAME, luaopen_table},
  29. {LUA_DBLIBNAME, luaopen_debug},
  30. #endif
  31. #if defined(LUA_EXLIBS_ROM)
  32. #undef _ROM
  33. #define _ROM( name, openf, table ) { name, openf },
  34. LUA_EXLIBS_ROM
  35. #endif
  36. {NULL, NULL}
  37. };
  38. extern const luaR_entry strlib[];
  39. extern const luaR_entry syslib[];
  40. extern const luaR_entry tab_funcs[];
  41. extern const luaR_entry dblib[];
  42. extern const luaR_entry co_funcs[];
  43. #if defined(LUA_EXLIBS_ROM) && LUA_OPTIMIZE_MEMORY == 2
  44. #undef _ROM
  45. #define _ROM( name, openf, table ) extern const luaR_entry table[];
  46. LUA_EXLIBS_ROM
  47. #endif
  48. const luaR_table lua_rotable[] =
  49. {
  50. #if LUA_OPTIMIZE_MEMORY > 0
  51. {LUA_STRLIBNAME, strlib},
  52. {LUA_TABLIBNAME, tab_funcs},
  53. {LUA_DBLIBNAME, dblib},
  54. {LUA_COLIBNAME, co_funcs},
  55. #if defined(LUA_EXLIBS_ROM) && LUA_OPTIMIZE_MEMORY == 2
  56. #undef _ROM
  57. #define _ROM( name, openf, table ) { name, table },
  58. LUA_EXLIBS_ROM
  59. #endif
  60. #endif
  61. {NULL, NULL}
  62. };
  63. LUALIB_API void luaL_openlibs (lua_State *L) {
  64. const luaL_Reg *lib = lualibs;
  65. for (; lib->func; lib++) {
  66. lua_pushcfunction(L, lib->func);
  67. lua_pushstring(L, lib->name);
  68. lua_call(L, 1, 0);
  69. }
  70. }