diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-09-05 09:39:29 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-09-05 09:39:29 -0300 |
| commit | 90e2a716c87c15f55872f0e27cdf3611da936bfb (patch) | |
| tree | 465a2e7e3db871c0e5beab2e04c166a63c4b951b | |
| parent | d9fbbe1f23554719ade2f870d0992e831719edc9 (diff) | |
| download | lua-90e2a716c87c15f55872f0e27cdf3611da936bfb.tar.gz lua-90e2a716c87c15f55872f0e27cdf3611da936bfb.tar.bz2 lua-90e2a716c87c15f55872f0e27cdf3611da936bfb.zip | |
details + comments
| -rw-r--r-- | linit.c | 22 |
1 files changed, 15 insertions, 7 deletions
| @@ -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 | */ |
| 20 | static const luaL_Reg loadedlibs[] = { | 29 | static 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 | ||
| 42 | LUALIB_API void luaL_openlibs (lua_State *L) { | 51 | LUALIB_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 | } |
