Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

73 wiersze
1.8 KiB

  1. /*
  2. ** $Id: linit.c,v 1.32 2011/04/08 19:17:36 roberto Exp $
  3. ** Initialization of libraries for lua.c and other clients
  4. ** See Copyright Notice in lua.h
  5. */
  6. #if defined HAVE_CONFIG_H // LOL BEGIN
  7. # include "config.h"
  8. #endif // LOL END
  9. /*
  10. ** If you embed Lua in your program and need to open the standard
  11. ** libraries, call luaL_openlibs in your program. If you need a
  12. ** different set of libraries, copy this file to your project and edit
  13. ** it to suit your needs.
  14. */
  15. #define linit_c
  16. #define LUA_LIB
  17. #include "lua.h"
  18. #include "lualib.h"
  19. #include "lauxlib.h"
  20. /*
  21. ** these libs are loaded by lua.c and are readily available to any Lua
  22. ** program
  23. */
  24. static const luaL_Reg loadedlibs[] = {
  25. {"_G", luaopen_base},
  26. {LUA_LOADLIBNAME, luaopen_package},
  27. {LUA_COLIBNAME, luaopen_coroutine},
  28. {LUA_TABLIBNAME, luaopen_table},
  29. #if 0 // LOL BEGIN
  30. {LUA_IOLIBNAME, luaopen_io},
  31. {LUA_OSLIBNAME, luaopen_os},
  32. #endif // LOL END
  33. {LUA_STRLIBNAME, luaopen_string},
  34. {LUA_BITLIBNAME, luaopen_bit32},
  35. {LUA_MATHLIBNAME, luaopen_math},
  36. {LUA_DBLIBNAME, luaopen_debug},
  37. {NULL, NULL}
  38. };
  39. /*
  40. ** these libs are preloaded and must be required before used
  41. */
  42. static const luaL_Reg preloadedlibs[] = {
  43. {NULL, NULL}
  44. };
  45. LUALIB_API void luaL_openlibs (lua_State *L) {
  46. const luaL_Reg *lib;
  47. /* call open functions from 'loadedlibs' and set results to global table */
  48. for (lib = loadedlibs; lib->func; lib++) {
  49. luaL_requiref(L, lib->name, lib->func, 1);
  50. lua_pop(L, 1); /* remove lib */
  51. }
  52. /* add open functions from 'preloadedlibs' into 'package.preload' table */
  53. luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD");
  54. for (lib = preloadedlibs; lib->func; lib++) {
  55. lua_pushcfunction(L, lib->func);
  56. lua_setfield(L, -2, lib->name);
  57. }
  58. lua_pop(L, 1); /* remove _PRELOAD table */
  59. }