diff options
author | Lua Team <team@lua.org> | 2014-12-11 12:00:00 +0000 |
---|---|---|
committer | repogen <> | 2014-12-11 12:00:00 +0000 |
commit | fd9a52f7ff522a363ff2495d33b331c221981d60 (patch) | |
tree | a3fca3cc276f2a2ee44a498984497a9b82e685ee /src/linit.c | |
parent | 92fdb95364ed274752b8634c8ba3dca1f1dc5fb3 (diff) | |
download | lua-github-5.3.0-rc0.tar.gz |
Lua 5.3.0-rc05.3.0-rc0
Diffstat (limited to 'src/linit.c')
-rw-r--r-- | src/linit.c | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/src/linit.c b/src/linit.c index 904aca9a..ca9d100d 100644 --- a/src/linit.c +++ b/src/linit.c @@ -1,21 +1,32 @@ /* -** $Id: linit.c,v 1.34 2014/05/15 19:28:34 roberto Exp $ +** $Id: linit.c,v 1.37 2014/12/09 15:00:17 roberto Exp $ ** Initialization of libraries for lua.c and other clients ** See Copyright Notice in lua.h */ +#define linit_c +#define LUA_LIB + +#include "lprefix.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. +** +** 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 */ - -#define linit_c -#define LUA_LIB - #include "lua.h" #include "lualib.h" @@ -35,8 +46,8 @@ static const luaL_Reg loadedlibs[] = { {LUA_OSLIBNAME, luaopen_os}, {LUA_STRLIBNAME, luaopen_string}, {LUA_MATHLIBNAME, luaopen_math}, - {LUA_DBLIBNAME, luaopen_debug}, {LUA_UTF8LIBNAME, luaopen_utf8}, + {LUA_DBLIBNAME, luaopen_debug}, #if defined(LUA_COMPAT_BITLIB) {LUA_BITLIBNAME, luaopen_bit32}, #endif @@ -44,27 +55,12 @@ static const luaL_Reg loadedlibs[] = { }; -/* -** these libs are preloaded and must be required before used -*/ -static const luaL_Reg preloadedlibs[] = { - {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 */ } |