diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-06-27 14:24:40 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-06-27 14:24:40 -0300 |
| commit | 2f0955b99b2f94f846d0e39fa32acb758fb3556f (patch) | |
| tree | 5b27431e74a3adf4f6c30fa3163d47b402a05a65 | |
| parent | 999d55d887079af989d07d747b3b354f0055fb5c (diff) | |
| download | lua-2f0955b99b2f94f846d0e39fa32acb758fb3556f.tar.gz lua-2f0955b99b2f94f846d0e39fa32acb758fb3556f.tar.bz2 lua-2f0955b99b2f94f846d0e39fa32acb758fb3556f.zip | |
detail
| -rw-r--r-- | loadlib.c | 10 |
1 files changed, 5 insertions, 5 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: loadlib.c,v 1.28 2005/05/17 19:49:15 roberto Exp roberto $ | 2 | ** $Id: loadlib.c,v 1.29 2005/05/20 19:09:05 roberto Exp roberto $ |
| 3 | ** Dynamic library loader for Lua | 3 | ** Dynamic library loader for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | ** | 5 | ** |
| @@ -374,10 +374,7 @@ static int ll_require (lua_State *L) { | |||
| 374 | lua_getfield(L, 2, name); | 374 | lua_getfield(L, 2, name); |
| 375 | if (lua_toboolean(L, -1)) /* is it there? */ | 375 | if (lua_toboolean(L, -1)) /* is it there? */ |
| 376 | return 1; /* package is already loaded; return its result */ | 376 | return 1; /* package is already loaded; return its result */ |
| 377 | /* else must load it; first mark it as loaded */ | 377 | /* else must load it; iterate over available loaders */ |
| 378 | lua_pushboolean(L, 1); | ||
| 379 | lua_setfield(L, 2, name); /* _LOADED[name] = true */ | ||
| 380 | /* iterate over available loaders */ | ||
| 381 | lua_getfield(L, LUA_ENVIRONINDEX, "loaders"); | 378 | lua_getfield(L, LUA_ENVIRONINDEX, "loaders"); |
| 382 | if (!lua_istable(L, -1)) | 379 | if (!lua_istable(L, -1)) |
| 383 | luaL_error(L, LUA_QL("package.loaders") " must be a table"); | 380 | luaL_error(L, LUA_QL("package.loaders") " must be a table"); |
| @@ -390,6 +387,9 @@ static int ll_require (lua_State *L) { | |||
| 390 | if (lua_isnil(L, -1)) lua_pop(L, 1); | 387 | if (lua_isnil(L, -1)) lua_pop(L, 1); |
| 391 | else break; /* module loaded successfully */ | 388 | else break; /* module loaded successfully */ |
| 392 | } | 389 | } |
| 390 | /* mark module as loaded */ | ||
| 391 | lua_pushboolean(L, 1); | ||
| 392 | lua_setfield(L, 2, name); /* _LOADED[name] = true */ | ||
| 393 | lua_pushvalue(L, 1); /* pass name as argument to module */ | 393 | lua_pushvalue(L, 1); /* pass name as argument to module */ |
| 394 | lua_call(L, 1, 1); /* run loaded module */ | 394 | lua_call(L, 1, 1); /* run loaded module */ |
| 395 | if (!lua_isnil(L, -1)) /* non-nil return? */ | 395 | if (!lua_isnil(L, -1)) /* non-nil return? */ |
