diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-07-16 11:51:36 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-07-16 11:51:36 -0300 |
commit | c229ed597f939eacfe1e9b7113e2a082fe93a3ae (patch) | |
tree | ee78d0fbdb485b54099820da90e97ab24a881c56 /ltests.c | |
parent | 16b41105215e3cad719ffb121caca0d065e05b6e (diff) | |
download | lua-c229ed597f939eacfe1e9b7113e2a082fe93a3ae.tar.gz lua-c229ed597f939eacfe1e9b7113e2a082fe93a3ae.tar.bz2 lua-c229ed597f939eacfe1e9b7113e2a082fe93a3ae.zip |
'requiref' checks 'package.loaded' before loading a module
Diffstat (limited to 'ltests.c')
-rw-r--r-- | ltests.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 2.173 2014/06/19 18:29:30 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.174 2014/06/26 17:25:11 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -839,7 +839,12 @@ static int loadlib (lua_State *L) { | |||
839 | }; | 839 | }; |
840 | lua_State *L1 = getstate(L); | 840 | lua_State *L1 = getstate(L); |
841 | int i; | 841 | int i; |
842 | luaL_requiref(L1, "package", luaopen_package, 1); | 842 | luaL_requiref(L1, "package", luaopen_package, 0); |
843 | lua_assert(lua_type(L1, -1) == LUA_TTABLE); | ||
844 | /* 'requiref' should not reload module already loaded... */ | ||
845 | luaL_requiref(L1, "package", NULL, 1); /* seg. fault if it reloads */ | ||
846 | /* ...but should return the same module */ | ||
847 | lua_assert(lua_compare(L1, -1, -2, LUA_OPEQ)); | ||
843 | luaL_getsubtable(L1, LUA_REGISTRYINDEX, "_PRELOAD"); | 848 | luaL_getsubtable(L1, LUA_REGISTRYINDEX, "_PRELOAD"); |
844 | for (i = 0; libs[i].name; i++) { | 849 | for (i = 0; libs[i].name; i++) { |
845 | lua_pushcfunction(L1, libs[i].func); | 850 | lua_pushcfunction(L1, libs[i].func); |