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 @@
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** Dynamic library loader for Lua3** Dynamic library loader for Lua
4** See Copyright Notice in lua.h4** 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 environment34** LUA_PATH_VAR and LUA_CPATH_VAR are the names of the environment
35** variables that Lua check to set its paths.35** variables that Lua check to set its paths.
36*/36*/
37#if !defined(LUA_PATH)37#if !defined(LUA_PATH_VAR)
38#define LUA_PATH "LUA_PATH"38#define LUA_PATH_VAR "LUA_PATH"
39#endif39#endif
40 40
41#if !defined(LUA_CPATH)41#if !defined(LUA_CPATH_VAR)
42#define LUA_CPATH "LUA_CPATH"42#define LUA_CPATH_VAR "LUA_CPATH"
43#endif43#endif
44 44
45#define LUA_PATHSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR45#define LUA_PATHSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR
46 46
47#define LUA_PATHVERSION LUA_PATH LUA_PATHSUFFIX47#define LUA_PATHVARVERSION LUA_PATH_VAR LUA_PATHSUFFIX
48#define LUA_CPATHVERSION LUA_CPATH LUA_PATHSUFFIX48#define LUA_CPATHVARVERSION LUA_CPATH_VAR LUA_PATHSUFFIX
49 49
50/*50/*
51** LUA_PATH_SEP is the character that separates templates in a path.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
468static int searcher_preload (lua_State *L) {468static 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) { · 8 unmodified lines
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) { · 28 unmodified lines
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) { · 59 unmodified lines
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);
@@ -703,9 +699,9 @@ LUAMOD_API int luaopen_package (lua_State *L) { · 107 unmodified lines
703#endif699#endif
704 lua_setfield(L, -2, "searchers"); /* put it in field 'searchers' */700 lua_setfield(L, -2, "searchers"); /* put it in field 'searchers' */
705 /* set field 'path' */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 /* set field 'cpath' */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 /* store config information */705 /* store config information */
710 lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATH_SEP "\n" LUA_PATH_MARK "\n"706 lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATH_SEP "\n" LUA_PATH_MARK "\n"
711 LUA_EXEC_DIR "\n" LUA_IGMARK "\n");707 LUA_EXEC_DIR "\n" LUA_IGMARK "\n");