linit.c 1.8 KB

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