aboutsummaryrefslogtreecommitdiff
path: root/linit.c
diff options
context:
space:
mode:
Diffstat (limited to 'linit.c')
-rw-r--r--linit.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/linit.c b/linit.c
index 63dc8f9d..7623b556 100644
--- a/linit.c
+++ b/linit.c
@@ -1,10 +1,18 @@
1/* 1/*
2** $Id: linit.c,v 1.18 2009/05/01 13:46:35 roberto Exp roberto $ 2** $Id: linit.c,v 1.19 2009/07/01 16:16:40 roberto Exp roberto $
3** Initialization of libraries for lua.c 3** Initialization of libraries for lua.c and other clients
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
6 6
7 7
8/*
9** If you embed Lua in your program and need to open the standard
10** libraries, call luaL_openlibs in your program. If you need a
11** different set of libraries, copy this file to your project and edit
12** it to suit your needs.
13*/
14
15
8#define linit_c 16#define linit_c
9#define LUA_LIB 17#define LUA_LIB
10 18
@@ -15,7 +23,8 @@
15 23
16 24
17/* 25/*
18** these libs are loaded by lua.c and are readily available to any program 26** these libs are loaded by lua.c and are readily available to any Lua
27** program
19*/ 28*/
20static const luaL_Reg loadedlibs[] = { 29static const luaL_Reg loadedlibs[] = {
21 {"_G", luaopen_base}, 30 {"_G", luaopen_base},
@@ -40,17 +49,16 @@ static const luaL_Reg preloadedlibs[] = {
40 49
41 50
42LUALIB_API void luaL_openlibs (lua_State *L) { 51LUALIB_API void luaL_openlibs (lua_State *L) {
52 const luaL_Reg *lib;
43 /* call open functions from 'loadedlibs' */ 53 /* call open functions from 'loadedlibs' */
44 const luaL_Reg *lib = loadedlibs; 54 for (lib = loadedlibs; lib->func; lib++) {
45 for (; lib->func; lib++) {
46 lua_pushcfunction(L, lib->func); 55 lua_pushcfunction(L, lib->func);
47 lua_pushstring(L, lib->name); 56 lua_pushstring(L, lib->name);
48 lua_call(L, 1, 0); 57 lua_call(L, 1, 0);
49 } 58 }
50 /* add open functions from 'preloadedlibs' into 'package.preload' table */ 59 /* add open functions from 'preloadedlibs' into 'package.preload' table */
51 lib = preloadedlibs;
52 luaL_findtable(L, LUA_GLOBALSINDEX, "package.preload", 0); 60 luaL_findtable(L, LUA_GLOBALSINDEX, "package.preload", 0);
53 for (; lib->func; lib++) { 61 for (lib = preloadedlibs; lib->func; lib++) {
54 lua_pushcfunction(L, lib->func); 62 lua_pushcfunction(L, lib->func);
55 lua_setfield(L, -2, lib->name); 63 lua_setfield(L, -2, lib->name);
56 } 64 }