commit 36efa6a6b923df9452526b166e8e8561ddf8b07e
parent c6e74e41c9752c8dc9a409e12cb2ae53e92679dd
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Tue, 9 Dec 2014 12:59:52 -0200
no more 'preloadedlibs' when opening libraries (as it is dead code now)
Diffstat:
2 files changed, 12 insertions(+), 26 deletions(-)
diff --git a/linit.c b/linit.c
@@ -1,5 +1,5 @@
/*
-** $Id: linit.c,v 1.35 2014/11/02 19:19:04 roberto Exp roberto $
+** $Id: linit.c,v 1.36 2014/12/06 20:42:58 roberto Exp roberto $
** Initialization of libraries for lua.c and other clients
** See Copyright Notice in lua.h
*/
@@ -16,6 +16,15 @@
** libraries, call luaL_openlibs in your program. If you need a
** different set of libraries, copy this file to your project and edit
** it to suit your needs.
+**
+** You can also *preload* libraries, so that a later 'require' can
+** open the library, which is already linked to the application.
+** For that, do the following code:
+**
+** luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD");
+** lua_pushcfunction(L, luaopen_modname);
+** lua_setfield(L, -2, modname);
+** lua_pop(L, 1); // remove _PRELOAD table
*/
#include "lua.h"
@@ -38,9 +47,7 @@ static const luaL_Reg loadedlibs[] = {
{LUA_STRLIBNAME, luaopen_string},
{LUA_MATHLIBNAME, luaopen_math},
{LUA_UTF8LIBNAME, luaopen_utf8},
-#if !defined(LUA_NODEBUGLIB)
{LUA_DBLIBNAME, luaopen_debug},
-#endif
#if defined(LUA_COMPAT_BITLIB)
{LUA_BITLIBNAME, luaopen_bit32},
#endif
@@ -48,30 +55,12 @@ static const luaL_Reg loadedlibs[] = {
};
-/*
-** these libs are preloaded and must be required before used
-*/
-static const luaL_Reg preloadedlibs[] = {
-#if defined(LUA_NODEBUGLIB)
- {LUA_DBLIBNAME, luaopen_debug},
-#endif
- {NULL, NULL}
-};
-
-
LUALIB_API void luaL_openlibs (lua_State *L) {
const luaL_Reg *lib;
- /* call open functions from 'loadedlibs' and set results to global table */
+ /* "require" functions from 'loadedlibs' and set results to global table */
for (lib = loadedlibs; lib->func; lib++) {
luaL_requiref(L, lib->name, lib->func, 1);
lua_pop(L, 1); /* remove lib */
}
- /* add open functions from 'preloadedlibs' into 'package.preload' table */
- luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD");
- for (lib = preloadedlibs; lib->func; lib++) {
- lua_pushcfunction(L, lib->func);
- lua_setfield(L, -2, lib->name);
- }
- lua_pop(L, 1); /* remove _PRELOAD table */
}
diff --git a/ltests.h b/ltests.h
@@ -1,5 +1,5 @@
/*
-** $Id: ltests.h,v 2.42 2014/11/29 19:45:37 roberto Exp roberto $
+** $Id: ltests.h,v 2.43 2014/12/06 20:42:58 roberto Exp roberto $
** Internal Header for Debugging of the Lua Implementation
** See Copyright Notice in lua.h
*/
@@ -24,9 +24,6 @@
#undef LUA_COMPAT_MODULE
-/* test without preloding debug library */
-#define LUA_NODEBUGLIB
-
#define LUA_DEBUG