diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-03-08 10:37:55 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-03-08 10:37:55 -0300 |
commit | 2d5b923759a77d8f5f7bfa62906ea37f46b9281d (patch) | |
tree | 07fb96bdd97f252c939d5adb50176a3c9d04315c /linit.c | |
parent | 192d1854920a568abf951d18ebb8f8c057a45caf (diff) | |
download | lua-2d5b923759a77d8f5f7bfa62906ea37f46b9281d.tar.gz lua-2d5b923759a77d8f5f7bfa62906ea37f46b9281d.tar.bz2 lua-2d5b923759a77d8f5f7bfa62906ea37f46b9281d.zip |
details
Diffstat (limited to 'linit.c')
-rw-r--r-- | linit.c | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: linit.c,v 1.8 2004/07/09 15:47:48 roberto Exp roberto $ | 2 | ** $Id: linit.c,v 1.9 2005/02/18 12:40:02 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 | */ |
@@ -29,12 +29,15 @@ static const luaL_reg lualibs[] = { | |||
29 | 29 | ||
30 | LUALIB_API int luaopen_stdlibs (lua_State *L) { | 30 | LUALIB_API int luaopen_stdlibs (lua_State *L) { |
31 | const luaL_reg *lib = lualibs; | 31 | const luaL_reg *lib = lualibs; |
32 | int t = lua_gettop(L); | ||
33 | lua_pushvalue(L, LUA_ENVIRONINDEX); /* save original environment */ | ||
32 | for (; lib->func; lib++) { | 34 | for (; lib->func; lib++) { |
33 | lib->func(L); /* open library */ | 35 | lib->func(L); /* open library */ |
34 | lua_settop(L, 0); /* discard any results */ | 36 | lua_settop(L, t + 1); /* discard any results */ |
35 | lua_pushvalue(L, LUA_GLOBALSINDEX); | 37 | lua_pushvalue(L, -1); |
36 | lua_replace(L, LUA_ENVIRONINDEX); /* restore environment */ | 38 | lua_replace(L, LUA_ENVIRONINDEX); /* restore environment */ |
37 | } | 39 | } |
38 | return 0; | 40 | lua_pop(L, 1); |
41 | return 0; | ||
39 | } | 42 | } |
40 | 43 | ||