Showing the changes to src/loadlib.c (1 of 60 files). Show all
Unified · Split
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: loadlib.c,v 1.111 2012/05/30 12:33:44 roberto Exp $ | |
| 2 | +** $Id: loadlib.c,v 1.113 2014/03/12 20:57:40 roberto Exp $ | |
| 3 | 3 | ** Dynamic library loader for Lua |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | ** |
| @@ -31,21 +31,21 @@ · 25 unmodified lines | ||
| 31 | 31 | |
| 32 | 32 | |
| 33 | 33 | /* |
| 34 | −** LUA_PATH and LUA_CPATH are the names of the environment | |
| 34 | +** LUA_PATH_VAR and LUA_CPATH_VAR are the names of the environment | |
| 35 | 35 | ** variables that Lua check to set its paths. |
| 36 | 36 | */ |
| 37 | −#if !defined(LUA_PATH) | |
| 38 | −#define LUA_PATH "LUA_PATH" | |
| 37 | +#if !defined(LUA_PATH_VAR) | |
| 38 | +#define LUA_PATH_VAR "LUA_PATH" | |
| 39 | 39 | #endif |
| 40 | 40 | |
| 41 | −#if !defined(LUA_CPATH) | |
| 42 | −#define LUA_CPATH "LUA_CPATH" | |
| 41 | +#if !defined(LUA_CPATH_VAR) | |
| 42 | +#define LUA_CPATH_VAR "LUA_CPATH" | |
| 43 | 43 | #endif |
| 44 | 44 | |
| 45 | 45 | #define LUA_PATHSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR |
| 46 | 46 | |
| 47 | −#define LUA_PATHVERSION LUA_PATH LUA_PATHSUFFIX | |
| 48 | −#define LUA_CPATHVERSION LUA_CPATH LUA_PATHSUFFIX | |
| 47 | +#define LUA_PATHVARVERSION LUA_PATH_VAR LUA_PATHSUFFIX | |
| 48 | +#define LUA_CPATHVARVERSION LUA_CPATH_VAR LUA_PATHSUFFIX | |
| 49 | 49 | |
| 50 | 50 | /* |
| 51 | 51 | ** LUA_PATH_SEP is the character that separates templates in a path. |
| @@ -468,8 +468,7 @@ static int searcher_Croot (lua_State *L) { · 416 unmodified lines | ||
| 468 | 468 | static int searcher_preload (lua_State *L) { |
| 469 | 469 | const char *name = luaL_checkstring(L, 1); |
| 470 | 470 | lua_getfield(L, LUA_REGISTRYINDEX, "_PRELOAD"); |
| 471 | − lua_getfield(L, -1, name); | |
| 472 | − if (lua_isnil(L, -1)) /* not found? */ | |
| 471 | + if (lua_getfield(L, -1, name) == LUA_TNIL) /* not found? */ | |
| 473 | 472 | lua_pushfstring(L, "\n\tno field package.preload['%s']", name); |
| 474 | 473 | return 1; |
| 475 | 474 | } |
| @@ -484,8 +483,7 @@ static void findloader (lua_State *L, const char *name) { · 8 unmodified lines | ||
| 484 | 483 | luaL_error(L, LUA_QL("package.searchers") " must be a table"); |
| 485 | 484 | /* iterate over available searchers to find a loader */ |
| 486 | 485 | for (i = 1; ; i++) { |
| 487 | − lua_rawgeti(L, 3, i); /* get a searcher */ | |
| 488 | − if (lua_isnil(L, -1)) { /* no more searchers? */ | |
| 486 | + if (lua_rawgeti(L, 3, i) == LUA_TNIL) { /* no more searchers? */ | |
| 489 | 487 | lua_pop(L, 1); /* remove nil */ |
| 490 | 488 | luaL_pushresult(&msg); /* create error message */ |
| 491 | 489 | luaL_error(L, "module " LUA_QS " not found:%s", |
| @@ -520,8 +518,7 @@ static int ll_require (lua_State *L) { · 28 unmodified lines | ||
| 520 | 518 | lua_call(L, 2, 1); /* run loader to load module */ |
| 521 | 519 | if (!lua_isnil(L, -1)) /* non-nil return? */ |
| 522 | 520 | lua_setfield(L, 2, name); /* _LOADED[name] = returned value */ |
| 523 | − lua_getfield(L, 2, name); | |
| 524 | − if (lua_isnil(L, -1)) { /* module did not set a value? */ | |
| 521 | + if (lua_getfield(L, 2, name) == LUA_TNIL) { /* module set no value? */ | |
| 525 | 522 | lua_pushboolean(L, 1); /* use true as result */ |
| 526 | 523 | lua_pushvalue(L, -1); /* extra copy to be returned */ |
| 527 | 524 | lua_setfield(L, 2, name); /* _LOADED[name] = true */ |
| @@ -587,9 +584,8 @@ static int ll_module (lua_State *L) { · 59 unmodified lines | ||
| 587 | 584 | int lastarg = lua_gettop(L); /* last parameter */ |
| 588 | 585 | luaL_pushmodule(L, modname, 1); /* get/create module table */ |
| 589 | 586 | /* check whether table already has a _NAME field */ |
| 590 | − lua_getfield(L, -1, "_NAME"); | |
| 591 | − if (!lua_isnil(L, -1)) /* is table an initialized module? */ | |
| 592 | − lua_pop(L, 1); | |
| 587 | + if (lua_getfield(L, -1, "_NAME") != LUA_TNIL) | |
| 588 | + lua_pop(L, 1); /* table is an initialized module */ | |
| 593 | 589 | else { /* no; initialize it */ |
| 594 | 590 | lua_pop(L, 1); |
| 595 | 591 | modinit(L, modname); |
| @@ -703,9 +699,9 @@ LUAMOD_API int luaopen_package (lua_State *L) { · 107 unmodified lines | ||
| 703 | 699 | #endif |
| 704 | 700 | lua_setfield(L, -2, "searchers"); /* put it in field 'searchers' */ |
| 705 | 701 | /* set field 'path' */ |
| 706 | − setpath(L, "path", LUA_PATHVERSION, LUA_PATH, LUA_PATH_DEFAULT); | |
| 702 | + setpath(L, "path", LUA_PATHVARVERSION, LUA_PATH_VAR, LUA_PATH_DEFAULT); | |
| 707 | 703 | /* set field 'cpath' */ |
| 708 | − setpath(L, "cpath", LUA_CPATHVERSION, LUA_CPATH, LUA_CPATH_DEFAULT); | |
| 704 | + setpath(L, "cpath", LUA_CPATHVARVERSION, LUA_CPATH_VAR, LUA_CPATH_DEFAULT); | |
| 709 | 705 | /* store config information */ |
| 710 | 706 | lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATH_SEP "\n" LUA_PATH_MARK "\n" |
| 711 | 707 | LUA_EXEC_DIR "\n" LUA_IGMARK "\n"); |