History

Lua 5.3.0-work2

Lua Team committed 12 years ago

Commit ad386d91 parent b83a40a60 files · +3280 −2672Browse files

Showing the changes to src/loadlib.c (1 of 60 files). Show all

Unified · Split

src/loadlib.c+15−19
@@ -1,5 +1,5 @@
11 /*
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 $
33 ** Dynamic library loader for Lua
44 ** See Copyright Notice in lua.h
55 **
@@ -31,21 +31,21 @@ · 25 unmodified lines
3131
3232
3333 /*
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
3535 ** variables that Lua check to set its paths.
3636 */
37−#if !defined(LUA_PATH)
38−#define LUA_PATH "LUA_PATH"
37+#if !defined(LUA_PATH_VAR)
38+#define LUA_PATH_VAR "LUA_PATH"
3939 #endif
4040
41−#if !defined(LUA_CPATH)
42−#define LUA_CPATH "LUA_CPATH"
41+#if !defined(LUA_CPATH_VAR)
42+#define LUA_CPATH_VAR "LUA_CPATH"
4343 #endif
4444
4545 #define LUA_PATHSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR
4646
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
4949
5050 /*
5151 ** 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
468468 static int searcher_preload (lua_State *L) {
469469 const char *name = luaL_checkstring(L, 1);
470470 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? */
473472 lua_pushfstring(L, "\n\tno field package.preload['%s']", name);
474473 return 1;
475474 }
@@ -484,8 +483,7 @@ static void findloader (lua_State *L, const char *name) { · 8 unmodified lines
484483 luaL_error(L, LUA_QL("package.searchers") " must be a table");
485484 /* iterate over available searchers to find a loader */
486485 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? */
489487 lua_pop(L, 1); /* remove nil */
490488 luaL_pushresult(&msg); /* create error message */
491489 luaL_error(L, "module " LUA_QS " not found:%s",
@@ -520,8 +518,7 @@ static int ll_require (lua_State *L) { · 28 unmodified lines
520518 lua_call(L, 2, 1); /* run loader to load module */
521519 if (!lua_isnil(L, -1)) /* non-nil return? */
522520 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? */
525522 lua_pushboolean(L, 1); /* use true as result */
526523 lua_pushvalue(L, -1); /* extra copy to be returned */
527524 lua_setfield(L, 2, name); /* _LOADED[name] = true */
@@ -587,9 +584,8 @@ static int ll_module (lua_State *L) { · 59 unmodified lines
587584 int lastarg = lua_gettop(L); /* last parameter */
588585 luaL_pushmodule(L, modname, 1); /* get/create module table */
589586 /* 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 */
593589 else { /* no; initialize it */
594590 lua_pop(L, 1);
595591 modinit(L, modname);
@@ -703,9 +699,9 @@ LUAMOD_API int luaopen_package (lua_State *L) { · 107 unmodified lines
703699 #endif
704700 lua_setfield(L, -2, "searchers"); /* put it in field 'searchers' */
705701 /* 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);
707703 /* 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);
709705 /* store config information */
710706 lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATH_SEP "\n" LUA_PATH_MARK "\n"
711707 LUA_EXEC_DIR "\n" LUA_IGMARK "\n");