lua

A copy of the Lua development repository
Log | Files | Refs | README

commit 2d5b923759a77d8f5f7bfa62906ea37f46b9281d
parent 192d1854920a568abf951d18ebb8f8c057a45caf
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Tue,  8 Mar 2005 10:37:33 -0300

details

Diffstat:
Mlinit.c | 11+++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/linit.c b/linit.c @@ -1,5 +1,5 @@ /* -** $Id: linit.c,v 1.8 2004/07/09 15:47:48 roberto Exp roberto $ +** $Id: linit.c,v 1.9 2005/02/18 12:40:02 roberto Exp roberto $ ** Initialization of libraries for lua.c ** See Copyright Notice in lua.h */ @@ -29,12 +29,15 @@ static const luaL_reg lualibs[] = { LUALIB_API int luaopen_stdlibs (lua_State *L) { const luaL_reg *lib = lualibs; + int t = lua_gettop(L); + lua_pushvalue(L, LUA_ENVIRONINDEX); /* save original environment */ for (; lib->func; lib++) { lib->func(L); /* open library */ - lua_settop(L, 0); /* discard any results */ - lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_settop(L, t + 1); /* discard any results */ + lua_pushvalue(L, -1); lua_replace(L, LUA_ENVIRONINDEX); /* restore environment */ } - return 0; + lua_pop(L, 1); + return 0; }