aboutsummaryrefslogtreecommitdiff
path: root/linit.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2007-06-22 13:59:11 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2007-06-22 13:59:11 -0300
commit3904a66ab0ea441504afb74160fb6ff5efd8d33b (patch)
tree0b96d4787fbc07f19a04c3dfe0831bbbf8158155 /linit.c
parentffc5f78229be51a31a8a75c09d5f8d35fb7654bb (diff)
downloadlua-3904a66ab0ea441504afb74160fb6ff5efd8d33b.tar.gz
lua-3904a66ab0ea441504afb74160fb6ff5efd8d33b.tar.bz2
lua-3904a66ab0ea441504afb74160fb6ff5efd8d33b.zip
'debug' library must be required before being used
Diffstat (limited to 'linit.c')
-rw-r--r--linit.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/linit.c b/linit.c
index 5f3ceda7..3b8fc1c6 100644
--- a/linit.c
+++ b/linit.c
@@ -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*/
17static const luaL_Reg lualibs[] = { 20static 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*/
35static 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