commit ec22fc963a9c80d81724ccdd17e967995fc988c9
parent c54f5f64c95d73de8a4b66592e6f033469b07fe4
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Thu, 26 Apr 2012 16:38:28 -0300
detail (separate code to create 'searchers' table into a new function)
Diffstat:
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/loadlib.c b/loadlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: loadlib.c,v 1.108 2011/12/12 16:34:03 roberto Exp roberto $
+** $Id: loadlib.c,v 1.109 2012/04/11 16:35:32 roberto Exp roberto $
** Dynamic library loader for Lua
** See Copyright Notice in lua.h
**
@@ -672,12 +672,22 @@ static const luaL_Reg ll_funcs[] = {
};
-static const lua_CFunction searchers[] =
- {searcher_preload, searcher_Lua, searcher_C, searcher_Croot, NULL};
+static void createsearcherstable (lua_State *L) {
+ static const lua_CFunction searchers[] =
+ {searcher_preload, searcher_Lua, searcher_C, searcher_Croot, NULL};
+ int i;
+ /* create 'searchers' table */
+ lua_createtable(L, sizeof(searchers)/sizeof(searchers[0]) - 1, 0);
+ /* fill it with pre-defined searchers */
+ for (i=0; searchers[i] != NULL; i++) {
+ lua_pushvalue(L, -2); /* set 'package' as upvalue for all searchers */
+ lua_pushcclosure(L, searchers[i], 1);
+ lua_rawseti(L, -2, i+1);
+ }
+}
LUAMOD_API int luaopen_package (lua_State *L) {
- int i;
/* create table CLIBS to keep track of loaded C libraries */
luaL_getsubtable(L, LUA_REGISTRYINDEX, CLIBS);
lua_createtable(L, 0, 1); /* metatable for CLIBS */
@@ -686,14 +696,7 @@ LUAMOD_API int luaopen_package (lua_State *L) {
lua_setmetatable(L, -2);
/* create `package' table */
luaL_newlib(L, pk_funcs);
- /* create 'searchers' table */
- lua_createtable(L, sizeof(searchers)/sizeof(searchers[0]) - 1, 0);
- /* fill it with pre-defined searchers */
- for (i=0; searchers[i] != NULL; i++) {
- lua_pushvalue(L, -2); /* set 'package' as upvalue for all searchers */
- lua_pushcclosure(L, searchers[i], 1);
- lua_rawseti(L, -2, i+1);
- }
+ createsearcherstable(L);
#if defined(LUA_COMPAT_LOADERS)
lua_pushvalue(L, -1); /* make a copy of 'searchers' table */
lua_setfield(L, -3, "loaders"); /* put it in field `loaders' */