| @@ -1,5 +1,5 @@ |
| 1 | /* | 1 | /* |
| 2 | ** $Id: loadlib.c,v 1.52 2006/04/10 18:27:23 roberto Exp $ | 2 | ** $Id: loadlib.c,v 1.54a 2006/07/03 20:16:49 roberto Exp $ |
| 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 | ** |
| @@ -16,9 +16,9 @@ · 10 unmodified lines |
| 16 | #define loadlib_c | 16 | #define loadlib_c |
| 17 | #define LUA_LIB | 17 | #define LUA_LIB |
| 18 | | 18 | |
| 19 | #include "lauxlib.h" | | |
| 20 | #include "lobject.h" | | |
| 21 | #include "lua.h" | 19 | #include "lua.h" |
| | 20 | |
| | 21 | #include "lauxlib.h" |
| 22 | #include "lualib.h" | 22 | #include "lualib.h" |
| 23 | | 23 | |
| 24 | | 24 | |
| @@ -356,15 +356,16 @@ static const char *findfile (lua_State *L, const char *name, · 331 unmodified lines |
| 356 | path = lua_tostring(L, -1); | 356 | path = lua_tostring(L, -1); |
| 357 | if (path == NULL) | 357 | if (path == NULL) |
| 358 | luaL_error(L, LUA_QL("package.%s") " must be a string", pname); | 358 | luaL_error(L, LUA_QL("package.%s") " must be a string", pname); |
| 359 | lua_pushstring(L, ""); /* error accumulator */ | 359 | lua_pushliteral(L, ""); /* error accumulator */ |
| 360 | while ((path = pushnexttemplate(L, path)) != NULL) { | 360 | while ((path = pushnexttemplate(L, path)) != NULL) { |
| 361 | const char *filename; | 361 | const char *filename; |
| 362 | filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name); | 362 | filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name); |
| | 363 | lua_remove(L, -2); /* remove path template */ |
| 363 | if (readable(filename)) /* does file exist and is readable? */ | 364 | if (readable(filename)) /* does file exist and is readable? */ |
| 364 | return filename; /* return that file name */ | 365 | return filename; /* return that file name */ |
| 365 | lua_pop(L, 2); /* remove path template and file name */ | 366 | lua_pushfstring(L, "\n\tno file " LUA_QS, filename); |
| 366 | luaO_pushfstring(L, "\n\tno file " LUA_QS, filename); | 367 | lua_remove(L, -2); /* remove file name */ |
| 367 | lua_concat(L, 2); | 368 | lua_concat(L, 2); /* add entry to possible error message */ |
| 368 | } | 369 | } |
| 369 | return NULL; /* not found */ | 370 | return NULL; /* not found */ |
| 370 | } | 371 | } |
| @@ -423,8 +424,8 @@ static int loader_Croot (lua_State *L) { · 52 unmodified lines |
| 423 | funcname = mkfuncname(L, name); | 424 | funcname = mkfuncname(L, name); |
| 424 | if ((stat = ll_loadfunc(L, filename, funcname)) != 0) { | 425 | if ((stat = ll_loadfunc(L, filename, funcname)) != 0) { |
| 425 | if (stat != ERRFUNC) loaderror(L, filename); /* real error */ | 426 | if (stat != ERRFUNC) loaderror(L, filename); /* real error */ |
| 426 | luaO_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS, | 427 | lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS, |
| 427 | name, filename); | 428 | name, filename); |
| 428 | return 1; /* function not found */ | 429 | return 1; /* function not found */ |
| 429 | } | 430 | } |
| 430 | return 1; | 431 | return 1; |
| @@ -438,7 +439,7 @@ static int loader_preload (lua_State *L) { · 7 unmodified lines |
| 438 | luaL_error(L, LUA_QL("package.preload") " must be a table"); | 439 | luaL_error(L, LUA_QL("package.preload") " must be a table"); |
| 439 | lua_getfield(L, -1, name); | 440 | lua_getfield(L, -1, name); |
| 440 | if (lua_isnil(L, -1)) /* not found? */ | 441 | if (lua_isnil(L, -1)) /* not found? */ |
| 441 | luaO_pushfstring(L, "\n\tno field package.preload['%s']", name); | 442 | lua_pushfstring(L, "\n\tno field package.preload['%s']", name); |
| 442 | return 1; | 443 | return 1; |
| 443 | } | 444 | } |
| 444 | | 445 | |
| @@ -462,7 +463,7 @@ static int ll_require (lua_State *L) { · 17 unmodified lines |
| 462 | lua_getfield(L, LUA_ENVIRONINDEX, "loaders"); | 463 | lua_getfield(L, LUA_ENVIRONINDEX, "loaders"); |
| 463 | if (!lua_istable(L, -1)) | 464 | if (!lua_istable(L, -1)) |
| 464 | luaL_error(L, LUA_QL("package.loaders") " must be a table"); | 465 | luaL_error(L, LUA_QL("package.loaders") " must be a table"); |
| 465 | lua_pushstring(L, ""); /* error message accumulator */ | 466 | lua_pushliteral(L, ""); /* error message accumulator */ |
| 466 | for (i=1; ; i++) { | 467 | for (i=1; ; i++) { |
| 467 | lua_rawgeti(L, -2, i); /* get a loader */ | 468 | lua_rawgeti(L, -2, i); /* get a loader */ |
| 468 | if (lua_isnil(L, -1)) | 469 | if (lua_isnil(L, -1)) |
| @@ -646,8 +647,8 @@ LUALIB_API int luaopen_package (lua_State *L) { · 177 unmodified lines |
| 646 | setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT); /* set field `path' */ | 647 | setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT); /* set field `path' */ |
| 647 | setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT); /* set field `cpath' */ | 648 | setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT); /* set field `cpath' */ |
| 648 | /* store config information */ | 649 | /* store config information */ |
| 649 | lua_pushstring(L, LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n" | 650 | lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n" |
| 650 | LUA_EXECDIR "\n" LUA_IGMARK); | 651 | LUA_EXECDIR "\n" LUA_IGMARK); |
| 651 | lua_setfield(L, -2, "config"); | 652 | lua_setfield(L, -2, "config"); |
| 652 | /* set field `loaded' */ | 653 | /* set field `loaded' */ |
| 653 | luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2); | 654 | luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2); |