diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-06-22 13:59:11 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-06-22 13:59:11 -0300 |
commit | 3904a66ab0ea441504afb74160fb6ff5efd8d33b (patch) | |
tree | 0b96d4787fbc07f19a04c3dfe0831bbbf8158155 | |
parent | ffc5f78229be51a31a8a75c09d5f8d35fb7654bb (diff) | |
download | lua-3904a66ab0ea441504afb74160fb6ff5efd8d33b.tar.gz lua-3904a66ab0ea441504afb74160fb6ff5efd8d33b.tar.bz2 lua-3904a66ab0ea441504afb74160fb6ff5efd8d33b.zip |
'debug' library must be required before being used
-rw-r--r-- | linit.c | 25 | ||||
-rw-r--r-- | luaconf.h | 10 |
2 files changed, 33 insertions, 2 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 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: luaconf.h,v 1.88 2007/05/03 20:49:29 roberto Exp roberto $ | 2 | ** $Id: luaconf.h,v 1.89 2007/06/21 13:48:04 roberto Exp roberto $ |
3 | ** Configuration file for Lua | 3 | ** Configuration file for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -334,6 +334,14 @@ | |||
334 | */ | 334 | */ |
335 | #define LUA_COMPAT_GFIND | 335 | #define LUA_COMPAT_GFIND |
336 | 336 | ||
337 | /* | ||
338 | @@ LUA_COMPAT_DEBUGLIB controls compatibility with preloading | ||
339 | @* the debug library. | ||
340 | ** CHANGE it to undefined as soon as you add 'require"debug"' everywhere | ||
341 | ** you need the debug library. | ||
342 | */ | ||
343 | #define LUA_COMPAT_DEBUGLIB | ||
344 | |||
337 | 345 | ||
338 | 346 | ||
339 | 347 | ||