diff options
Diffstat (limited to 'linit.c')
-rw-r--r-- | linit.c | 25 |
1 files changed, 24 insertions, 1 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: linit.c,v 1.13 2005/08/26 17:36:32 roberto Exp roberto $ | 2 | ** $Id: linit.c,v 1.14 2005/12/29 15:32:11 roberto Exp roberto $ |
3 | ** Initialization of libraries for lua.c | 3 | ** Initialization of libraries for lua.c |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -14,6 +14,9 @@ | |||
14 | #include "lauxlib.h" | 14 | #include "lauxlib.h" |
15 | 15 | ||
16 | 16 | ||
17 | /* | ||
18 | ** these libs are preloaded in Lua and are readily available to any program | ||
19 | */ | ||
17 | static const luaL_Reg lualibs[] = { | 20 | static const luaL_Reg lualibs[] = { |
18 | {"", luaopen_base}, | 21 | {"", luaopen_base}, |
19 | {LUA_LOADLIBNAME, luaopen_package}, | 22 | {LUA_LOADLIBNAME, luaopen_package}, |
@@ -22,6 +25,14 @@ static const luaL_Reg lualibs[] = { | |||
22 | {LUA_OSLIBNAME, luaopen_os}, | 25 | {LUA_OSLIBNAME, luaopen_os}, |
23 | {LUA_STRLIBNAME, luaopen_string}, | 26 | {LUA_STRLIBNAME, luaopen_string}, |
24 | {LUA_MATHLIBNAME, luaopen_math}, | 27 | {LUA_MATHLIBNAME, luaopen_math}, |
28 | {NULL, NULL} | ||
29 | }; | ||
30 | |||
31 | |||
32 | /* | ||
33 | ** these libs must be required before used | ||
34 | */ | ||
35 | static const luaL_Reg luareqlibs[] = { | ||
25 | {LUA_DBLIBNAME, luaopen_debug}, | 36 | {LUA_DBLIBNAME, luaopen_debug}, |
26 | {NULL, NULL} | 37 | {NULL, NULL} |
27 | }; | 38 | }; |
@@ -34,5 +45,17 @@ LUALIB_API void luaL_openlibs (lua_State *L) { | |||
34 | lua_pushstring(L, lib->name); | 45 | lua_pushstring(L, lib->name); |
35 | lua_call(L, 1, 0); | 46 | lua_call(L, 1, 0); |
36 | } | 47 | } |
48 | lib = luareqlibs; | ||
49 | luaL_findtable(L, LUA_GLOBALSINDEX, "package.preload", 0); | ||
50 | for (; lib->func; lib++) { | ||
51 | lua_pushcfunction(L, lib->func); | ||
52 | lua_setfield(L, -2, lib->name); | ||
53 | } | ||
54 | lua_pop(L, 1); /* remove package.preload table */ | ||
55 | #ifdef LUA_COMPAT_DEBUGLIB | ||
56 | lua_getglobal(L, "require"); | ||
57 | lua_pushliteral(L, LUA_DBLIBNAME); | ||
58 | lua_call(L, 1, 0); /* call 'require"debug"' */ | ||
59 | #endif | ||
37 | } | 60 | } |
38 | 61 | ||