From 2d5b923759a77d8f5f7bfa62906ea37f46b9281d Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 8 Mar 2005 10:37:55 -0300 Subject: [PATCH] details --- linit.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/linit.c b/linit.c index da414468..5d447c6d 100644 --- 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; }