diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-03-12 17:57:40 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-03-12 17:57:40 -0300 |
commit | a3addae03634794b841b6c8c4dd8ff83542d8896 (patch) | |
tree | 66695864f7bd56c295ad7cd6a6465845103cd424 /loadlib.c | |
parent | ad40bb1181d08821af6789147a28aa8370533d11 (diff) | |
download | lua-a3addae03634794b841b6c8c4dd8ff83542d8896.tar.gz lua-a3addae03634794b841b6c8c4dd8ff83542d8896.tar.bz2 lua-a3addae03634794b841b6c8c4dd8ff83542d8896.zip |
lua_gettable and similars return type of gotten value
Diffstat (limited to 'loadlib.c')
-rw-r--r-- | loadlib.c | 16 |
1 files changed, 6 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: loadlib.c,v 1.111 2012/05/30 12:33:44 roberto Exp roberto $ | 2 | ** $Id: loadlib.c,v 1.112 2013/10/07 14:20:31 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 | ** |
@@ -468,8 +468,7 @@ static int searcher_Croot (lua_State *L) { | |||
468 | static int searcher_preload (lua_State *L) { | 468 | static int searcher_preload (lua_State *L) { |
469 | const char *name = luaL_checkstring(L, 1); | 469 | const char *name = luaL_checkstring(L, 1); |
470 | lua_getfield(L, LUA_REGISTRYINDEX, "_PRELOAD"); | 470 | lua_getfield(L, LUA_REGISTRYINDEX, "_PRELOAD"); |
471 | lua_getfield(L, -1, name); | 471 | if (lua_getfield(L, -1, name) == LUA_TNIL) /* not found? */ |
472 | if (lua_isnil(L, -1)) /* not found? */ | ||
473 | lua_pushfstring(L, "\n\tno field package.preload['%s']", name); | 472 | lua_pushfstring(L, "\n\tno field package.preload['%s']", name); |
474 | return 1; | 473 | return 1; |
475 | } | 474 | } |
@@ -484,8 +483,7 @@ static void findloader (lua_State *L, const char *name) { | |||
484 | luaL_error(L, LUA_QL("package.searchers") " must be a table"); | 483 | luaL_error(L, LUA_QL("package.searchers") " must be a table"); |
485 | /* iterate over available searchers to find a loader */ | 484 | /* iterate over available searchers to find a loader */ |
486 | for (i = 1; ; i++) { | 485 | for (i = 1; ; i++) { |
487 | lua_rawgeti(L, 3, i); /* get a searcher */ | 486 | if (lua_rawgeti(L, 3, i) == LUA_TNIL) { /* no more searchers? */ |
488 | if (lua_isnil(L, -1)) { /* no more searchers? */ | ||
489 | lua_pop(L, 1); /* remove nil */ | 487 | lua_pop(L, 1); /* remove nil */ |
490 | luaL_pushresult(&msg); /* create error message */ | 488 | luaL_pushresult(&msg); /* create error message */ |
491 | luaL_error(L, "module " LUA_QS " not found:%s", | 489 | luaL_error(L, "module " LUA_QS " not found:%s", |
@@ -520,8 +518,7 @@ static int ll_require (lua_State *L) { | |||
520 | lua_call(L, 2, 1); /* run loader to load module */ | 518 | lua_call(L, 2, 1); /* run loader to load module */ |
521 | if (!lua_isnil(L, -1)) /* non-nil return? */ | 519 | if (!lua_isnil(L, -1)) /* non-nil return? */ |
522 | lua_setfield(L, 2, name); /* _LOADED[name] = returned value */ | 520 | lua_setfield(L, 2, name); /* _LOADED[name] = returned value */ |
523 | lua_getfield(L, 2, name); | 521 | if (lua_getfield(L, 2, name) == LUA_TNIL) { /* module set no value? */ |
524 | if (lua_isnil(L, -1)) { /* module did not set a value? */ | ||
525 | lua_pushboolean(L, 1); /* use true as result */ | 522 | lua_pushboolean(L, 1); /* use true as result */ |
526 | lua_pushvalue(L, -1); /* extra copy to be returned */ | 523 | lua_pushvalue(L, -1); /* extra copy to be returned */ |
527 | lua_setfield(L, 2, name); /* _LOADED[name] = true */ | 524 | lua_setfield(L, 2, name); /* _LOADED[name] = true */ |
@@ -587,9 +584,8 @@ static int ll_module (lua_State *L) { | |||
587 | int lastarg = lua_gettop(L); /* last parameter */ | 584 | int lastarg = lua_gettop(L); /* last parameter */ |
588 | luaL_pushmodule(L, modname, 1); /* get/create module table */ | 585 | luaL_pushmodule(L, modname, 1); /* get/create module table */ |
589 | /* check whether table already has a _NAME field */ | 586 | /* check whether table already has a _NAME field */ |
590 | lua_getfield(L, -1, "_NAME"); | 587 | if (lua_getfield(L, -1, "_NAME") != LUA_TNIL) |
591 | if (!lua_isnil(L, -1)) /* is table an initialized module? */ | 588 | lua_pop(L, 1); /* table is an initialized module */ |
592 | lua_pop(L, 1); | ||
593 | else { /* no; initialize it */ | 589 | else { /* no; initialize it */ |
594 | lua_pop(L, 1); | 590 | lua_pop(L, 1); |
595 | modinit(L, modname); | 591 | modinit(L, modname); |