diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2012-04-20 14:05:17 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2012-04-20 14:05:17 -0300 |
commit | 4cca1a436db7b425e28e3ef0bea8216bdcf02fb8 (patch) | |
tree | 0776500f783549299383890097d0648578a2cc04 /lua.c | |
parent | 8df0198178d12cc202a5db3608f3b8bc0e742400 (diff) | |
download | lua-github-4cca1a436db7b425e28e3ef0bea8216bdcf02fb8.tar.gz |
details (using lua_setglobal/lua_getglobal instead of explicit
use of the global table)
Diffstat (limited to 'lua.c')
-rw-r--r-- | lua.c | 15 |
1 files changed, 5 insertions, 10 deletions
@@ -1,5 +1,5 @@ /* -** $Id: lua.c,v 1.202 2011/08/17 20:19:52 roberto Exp roberto $ +** $Id: lua.c,v 1.203 2011/12/12 16:34:03 roberto Exp roberto $ ** Lua stand-alone interpreter ** See Copyright Notice in lua.h */ @@ -223,16 +223,11 @@ static int dostring (lua_State *L, const char *s, const char *name) { static int dolibrary (lua_State *L, const char *name) { int status; - lua_pushglobaltable(L); - lua_getfield(L, -1, "require"); + lua_getglobal(L, "require"); lua_pushstring(L, name); - status = docall(L, 1, 1); - if (status == LUA_OK) { - lua_setfield(L, -2, name); /* global[name] = require return */ - lua_pop(L, 1); /* remove global table */ - } - else - lua_remove(L, -2); /* remove global table (below error msg.) */ + status = docall(L, 1, 1); /* call 'require(name)' */ + if (status == LUA_OK) + lua_setglobal(L, name); /* global[name] = require return */ return report(L, status); } |