commit 90e2a716c87c15f55872f0e27cdf3611da936bfb
parent d9fbbe1f23554719ade2f870d0992e831719edc9
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Sat, 5 Sep 2009 09:39:05 -0300
details + comments
Diffstat:
M | linit.c | | | 22 | +++++++++++++++------- |
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/linit.c b/linit.c
@@ -1,10 +1,18 @@
/*
-** $Id: linit.c,v 1.18 2009/05/01 13:46:35 roberto Exp roberto $
-** Initialization of libraries for lua.c
+** $Id: linit.c,v 1.19 2009/07/01 16:16:40 roberto Exp roberto $
+** Initialization of libraries for lua.c and other clients
** See Copyright Notice in lua.h
*/
+/*
+** If you embed Lua in your program and need to open the standard
+** 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.
+*/
+
+
#define linit_c
#define LUA_LIB
@@ -15,7 +23,8 @@
/*
-** these libs are loaded by lua.c and are readily available to any program
+** these libs are loaded by lua.c and are readily available to any Lua
+** program
*/
static const luaL_Reg loadedlibs[] = {
{"_G", luaopen_base},
@@ -40,17 +49,16 @@ static const luaL_Reg preloadedlibs[] = {
LUALIB_API void luaL_openlibs (lua_State *L) {
+ const luaL_Reg *lib;
/* call open functions from 'loadedlibs' */
- const luaL_Reg *lib = loadedlibs;
- for (; lib->func; lib++) {
+ for (lib = loadedlibs; lib->func; lib++) {
lua_pushcfunction(L, lib->func);
lua_pushstring(L, lib->name);
lua_call(L, 1, 0);
}
/* add open functions from 'preloadedlibs' into 'package.preload' table */
- lib = preloadedlibs;
luaL_findtable(L, LUA_GLOBALSINDEX, "package.preload", 0);
- for (; lib->func; lib++) {
+ for (lib = preloadedlibs; lib->func; lib++) {
lua_pushcfunction(L, lib->func);
lua_setfield(L, -2, lib->name);
}