aboutsummaryrefslogtreecommitdiff
path: root/loadlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'loadlib.c')
-rw-r--r--loadlib.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/loadlib.c b/loadlib.c
index 24910351..16526603 100644
--- a/loadlib.c
+++ b/loadlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: loadlib.c,v 1.127 2015/11/23 11:30:45 roberto Exp roberto $ 2** $Id: loadlib.c,v 1.128 2016/07/18 17:55:59 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**
@@ -471,7 +471,7 @@ static int searcher_Croot (lua_State *L) {
471 471
472static int searcher_preload (lua_State *L) { 472static int searcher_preload (lua_State *L) {
473 const char *name = luaL_checkstring(L, 1); 473 const char *name = luaL_checkstring(L, 1);
474 lua_getfield(L, LUA_REGISTRYINDEX, "_PRELOAD"); 474 lua_getfield(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);
475 if (lua_getfield(L, -1, name) == LUA_TNIL) /* not found? */ 475 if (lua_getfield(L, -1, name) == LUA_TNIL) /* not found? */
476 lua_pushfstring(L, "\n\tno field package.preload['%s']", name); 476 lua_pushfstring(L, "\n\tno field package.preload['%s']", name);
477 return 1; 477 return 1;
@@ -508,9 +508,9 @@ static void findloader (lua_State *L, const char *name) {
508 508
509static int ll_require (lua_State *L) { 509static int ll_require (lua_State *L) {
510 const char *name = luaL_checkstring(L, 1); 510 const char *name = luaL_checkstring(L, 1);
511 lua_settop(L, 1); /* _LOADED table will be at index 2 */ 511 lua_settop(L, 1); /* LOADED table will be at index 2 */
512 lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); 512 lua_getfield(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);
513 lua_getfield(L, 2, name); /* _LOADED[name] */ 513 lua_getfield(L, 2, name); /* LOADED[name] */
514 if (lua_toboolean(L, -1)) /* is it there? */ 514 if (lua_toboolean(L, -1)) /* is it there? */
515 return 1; /* package is already loaded */ 515 return 1; /* package is already loaded */
516 /* else must load package */ 516 /* else must load package */
@@ -520,11 +520,11 @@ static int ll_require (lua_State *L) {
520 lua_insert(L, -2); /* name is 1st argument (before search data) */ 520 lua_insert(L, -2); /* name is 1st argument (before search data) */
521 lua_call(L, 2, 1); /* run loader to load module */ 521 lua_call(L, 2, 1); /* run loader to load module */
522 if (!lua_isnil(L, -1)) /* non-nil return? */ 522 if (!lua_isnil(L, -1)) /* non-nil return? */
523 lua_setfield(L, 2, name); /* _LOADED[name] = returned value */ 523 lua_setfield(L, 2, name); /* LOADED[name] = returned value */
524 if (lua_getfield(L, 2, name) == LUA_TNIL) { /* module set no value? */ 524 if (lua_getfield(L, 2, name) == LUA_TNIL) { /* module set no value? */
525 lua_pushboolean(L, 1); /* use true as result */ 525 lua_pushboolean(L, 1); /* use true as result */
526 lua_pushvalue(L, -1); /* extra copy to be returned */ 526 lua_pushvalue(L, -1); /* extra copy to be returned */
527 lua_setfield(L, 2, name); /* _LOADED[name] = true */ 527 lua_setfield(L, 2, name); /* LOADED[name] = true */
528 } 528 }
529 return 1; 529 return 1;
530} 530}
@@ -689,10 +689,10 @@ LUAMOD_API int luaopen_package (lua_State *L) {
689 LUA_EXEC_DIR "\n" LUA_IGMARK "\n"); 689 LUA_EXEC_DIR "\n" LUA_IGMARK "\n");
690 lua_setfield(L, -2, "config"); 690 lua_setfield(L, -2, "config");
691 /* set field 'loaded' */ 691 /* set field 'loaded' */
692 luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED"); 692 luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);
693 lua_setfield(L, -2, "loaded"); 693 lua_setfield(L, -2, "loaded");
694 /* set field 'preload' */ 694 /* set field 'preload' */
695 luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD"); 695 luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);
696 lua_setfield(L, -2, "preload"); 696 lua_setfield(L, -2, "preload");
697 lua_pushglobaltable(L); 697 lua_pushglobaltable(L);
698 lua_pushvalue(L, -2); /* set 'package' as upvalue for next lib */ 698 lua_pushvalue(L, -2); /* set 'package' as upvalue for next lib */