aboutsummaryrefslogtreecommitdiff
path: root/loadlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'loadlib.c')
-rw-r--r--loadlib.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/loadlib.c b/loadlib.c
index 2526096c..49b986de 100644
--- a/loadlib.c
+++ b/loadlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: loadlib.c,v 1.108 2011/12/12 16:34:03 roberto Exp roberto $ 2** $Id: loadlib.c,v 1.109 2012/04/11 16:35:32 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**
@@ -672,12 +672,22 @@ static const luaL_Reg ll_funcs[] = {
672}; 672};
673 673
674 674
675static const lua_CFunction searchers[] = 675static void createsearcherstable (lua_State *L) {
676 {searcher_preload, searcher_Lua, searcher_C, searcher_Croot, NULL}; 676 static const lua_CFunction searchers[] =
677 {searcher_preload, searcher_Lua, searcher_C, searcher_Croot, NULL};
678 int i;
679 /* create 'searchers' table */
680 lua_createtable(L, sizeof(searchers)/sizeof(searchers[0]) - 1, 0);
681 /* fill it with pre-defined searchers */
682 for (i=0; searchers[i] != NULL; i++) {
683 lua_pushvalue(L, -2); /* set 'package' as upvalue for all searchers */
684 lua_pushcclosure(L, searchers[i], 1);
685 lua_rawseti(L, -2, i+1);
686 }
687}
677 688
678 689
679LUAMOD_API int luaopen_package (lua_State *L) { 690LUAMOD_API int luaopen_package (lua_State *L) {
680 int i;
681 /* create table CLIBS to keep track of loaded C libraries */ 691 /* create table CLIBS to keep track of loaded C libraries */
682 luaL_getsubtable(L, LUA_REGISTRYINDEX, CLIBS); 692 luaL_getsubtable(L, LUA_REGISTRYINDEX, CLIBS);
683 lua_createtable(L, 0, 1); /* metatable for CLIBS */ 693 lua_createtable(L, 0, 1); /* metatable for CLIBS */
@@ -686,14 +696,7 @@ LUAMOD_API int luaopen_package (lua_State *L) {
686 lua_setmetatable(L, -2); 696 lua_setmetatable(L, -2);
687 /* create `package' table */ 697 /* create `package' table */
688 luaL_newlib(L, pk_funcs); 698 luaL_newlib(L, pk_funcs);
689 /* create 'searchers' table */ 699 createsearcherstable(L);
690 lua_createtable(L, sizeof(searchers)/sizeof(searchers[0]) - 1, 0);
691 /* fill it with pre-defined searchers */
692 for (i=0; searchers[i] != NULL; i++) {
693 lua_pushvalue(L, -2); /* set 'package' as upvalue for all searchers */
694 lua_pushcclosure(L, searchers[i], 1);
695 lua_rawseti(L, -2, i+1);
696 }
697#if defined(LUA_COMPAT_LOADERS) 700#if defined(LUA_COMPAT_LOADERS)
698 lua_pushvalue(L, -1); /* make a copy of 'searchers' table */ 701 lua_pushvalue(L, -1); /* make a copy of 'searchers' table */
699 lua_setfield(L, -3, "loaders"); /* put it in field `loaders' */ 702 lua_setfield(L, -3, "loaders"); /* put it in field `loaders' */