aboutsummaryrefslogtreecommitdiff
path: root/loadlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'loadlib.c')
-rw-r--r--loadlib.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/loadlib.c b/loadlib.c
index 2c1d87f2..1fe4fc38 100644
--- a/loadlib.c
+++ b/loadlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: loadlib.c,v 1.15 2004/12/29 18:56:34 roberto Exp roberto $ 2** $Id: loadlib.c,v 1.16 2005/01/14 14:17:18 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*
@@ -302,7 +302,7 @@ static int loader_Lua (lua_State *L) {
302 path = lua_tostring(L, -1); 302 path = lua_tostring(L, -1);
303 if (!path) { 303 if (!path) {
304 lua_pop(L, 1); 304 lua_pop(L, 1);
305 luaL_getfield(L, LUA_REGISTRYINDEX, "_PACKAGE.path"); 305 lua_getfield(L, LUA_ENVIRONINDEX, "path");
306 path = lua_tostring(L, -1); 306 path = lua_tostring(L, -1);
307 } 307 }
308 if (path == NULL) 308 if (path == NULL)
@@ -320,7 +320,7 @@ static int loader_C (lua_State *L) {
320 const char *fname = luaL_gsub(L, name, ".", LUA_DIRSEP); 320 const char *fname = luaL_gsub(L, name, ".", LUA_DIRSEP);
321 const char *path; 321 const char *path;
322 const char *funcname; 322 const char *funcname;
323 luaL_getfield(L, LUA_REGISTRYINDEX, "_PACKAGE.cpath"); 323 lua_getfield(L, LUA_ENVIRONINDEX, "cpath");
324 path = lua_tostring(L, -1); 324 path = lua_tostring(L, -1);
325 if (path == NULL) 325 if (path == NULL)
326 luaL_error(L, "`package.cpath' must be a string"); 326 luaL_error(L, "`package.cpath' must be a string");
@@ -335,7 +335,7 @@ static int loader_C (lua_State *L) {
335 335
336 336
337static int loader_preload (lua_State *L) { 337static int loader_preload (lua_State *L) {
338 luaL_getfield(L, LUA_REGISTRYINDEX, "_PACKAGE.preload"); 338 lua_getfield(L, LUA_ENVIRONINDEX, "preload");
339 if (!lua_istable(L, -1)) 339 if (!lua_istable(L, -1))
340 luaL_error(L, "`package.preload' must be a table"); 340 luaL_error(L, "`package.preload' must be a table");
341 lua_getfield(L, -1, luaL_checkstring(L, 1)); 341 lua_getfield(L, -1, luaL_checkstring(L, 1));
@@ -355,7 +355,7 @@ static int ll_require (lua_State *L) {
355 lua_pushboolean(L, 1); 355 lua_pushboolean(L, 1);
356 lua_setfield(L, 2, name); /* _LOADED[name] = true */ 356 lua_setfield(L, 2, name); /* _LOADED[name] = true */
357 /* iterate over available loaders */ 357 /* iterate over available loaders */
358 luaL_getfield(L, LUA_REGISTRYINDEX, "_PACKAGE.loaders"); 358 lua_getfield(L, LUA_ENVIRONINDEX, "loaders");
359 if (!lua_istable(L, -1)) 359 if (!lua_istable(L, -1))
360 luaL_error(L, "`package.loaders' must be a table"); 360 luaL_error(L, "`package.loaders' must be a table");
361 for (i=1;; i++) { 361 for (i=1;; i++) {
@@ -457,6 +457,8 @@ LUALIB_API int luaopen_loadlib (lua_State *L) {
457 lua_setglobal(L, "package"); 457 lua_setglobal(L, "package");
458 lua_pushvalue(L, -1); 458 lua_pushvalue(L, -1);
459 lua_setfield(L, LUA_REGISTRYINDEX, "_PACKAGE"); 459 lua_setfield(L, LUA_REGISTRYINDEX, "_PACKAGE");
460 lua_pushvalue(L, -1);
461 lua_replace(L, LUA_ENVIRONINDEX);
460 /* create `loaders' table */ 462 /* create `loaders' table */
461 lua_newtable(L); 463 lua_newtable(L);
462 /* fill it with pre-defined loaders */ 464 /* fill it with pre-defined loaders */