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 | |
parent | 8df0198178d12cc202a5db3608f3b8bc0e742400 (diff) | |
download | lua-4cca1a436db7b425e28e3ef0bea8216bdcf02fb8.tar.gz lua-4cca1a436db7b425e28e3ef0bea8216bdcf02fb8.tar.bz2 lua-4cca1a436db7b425e28e3ef0bea8216bdcf02fb8.zip |
details (using lua_setglobal/lua_getglobal instead of explicit
use of the global table)
-rw-r--r-- | lauxlib.c | 8 | ||||
-rw-r--r-- | lua.c | 15 |
2 files changed, 8 insertions, 15 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.241 2012/03/18 16:52:49 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.242 2012/03/19 22:57:14 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -892,10 +892,8 @@ LUALIB_API void luaL_requiref (lua_State *L, const char *modname, | |||
892 | lua_setfield(L, -2, modname); /* _LOADED[modname] = module */ | 892 | lua_setfield(L, -2, modname); /* _LOADED[modname] = module */ |
893 | lua_pop(L, 1); /* remove _LOADED table */ | 893 | lua_pop(L, 1); /* remove _LOADED table */ |
894 | if (glb) { | 894 | if (glb) { |
895 | lua_pushglobaltable(L); | 895 | lua_pushvalue(L, -1); /* copy of 'mod' */ |
896 | lua_pushvalue(L, -2); /* copy of 'mod' */ | 896 | lua_setglobal(L, modname); /* _G[modname] = module */ |
897 | lua_setfield(L, -2, modname); /* _G[modname] = module */ | ||
898 | lua_pop(L, 1); /* remove _G table */ | ||
899 | } | 897 | } |
900 | } | 898 | } |
901 | 899 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.c,v 1.202 2011/08/17 20:19:52 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.203 2011/12/12 16:34:03 roberto Exp roberto $ |
3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -223,16 +223,11 @@ static int dostring (lua_State *L, const char *s, const char *name) { | |||
223 | 223 | ||
224 | static int dolibrary (lua_State *L, const char *name) { | 224 | static int dolibrary (lua_State *L, const char *name) { |
225 | int status; | 225 | int status; |
226 | lua_pushglobaltable(L); | 226 | lua_getglobal(L, "require"); |
227 | lua_getfield(L, -1, "require"); | ||
228 | lua_pushstring(L, name); | 227 | lua_pushstring(L, name); |
229 | status = docall(L, 1, 1); | 228 | status = docall(L, 1, 1); /* call 'require(name)' */ |
230 | if (status == LUA_OK) { | 229 | if (status == LUA_OK) |
231 | lua_setfield(L, -2, name); /* global[name] = require return */ | 230 | lua_setglobal(L, name); /* global[name] = require return */ |
232 | lua_pop(L, 1); /* remove global table */ | ||
233 | } | ||
234 | else | ||
235 | lua_remove(L, -2); /* remove global table (below error msg.) */ | ||
236 | return report(L, status); | 231 | return report(L, status); |
237 | } | 232 | } |
238 | 233 | ||