1*088332b5SXin Li /*
2*088332b5SXin Li ** $Id: linit.c $
3*088332b5SXin Li ** Initialization of libraries for lua.c and other clients
4*088332b5SXin Li ** See Copyright Notice in lua.h
5*088332b5SXin Li */
6*088332b5SXin Li
7*088332b5SXin Li
8*088332b5SXin Li #define linit_c
9*088332b5SXin Li #define LUA_LIB
10*088332b5SXin Li
11*088332b5SXin Li /*
12*088332b5SXin Li ** If you embed Lua in your program and need to open the standard
13*088332b5SXin Li ** libraries, call luaL_openlibs in your program. If you need a
14*088332b5SXin Li ** different set of libraries, copy this file to your project and edit
15*088332b5SXin Li ** it to suit your needs.
16*088332b5SXin Li **
17*088332b5SXin Li ** You can also *preload* libraries, so that a later 'require' can
18*088332b5SXin Li ** open the library, which is already linked to the application.
19*088332b5SXin Li ** For that, do the following code:
20*088332b5SXin Li **
21*088332b5SXin Li ** luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);
22*088332b5SXin Li ** lua_pushcfunction(L, luaopen_modname);
23*088332b5SXin Li ** lua_setfield(L, -2, modname);
24*088332b5SXin Li ** lua_pop(L, 1); // remove PRELOAD table
25*088332b5SXin Li */
26*088332b5SXin Li
27*088332b5SXin Li #include "lprefix.h"
28*088332b5SXin Li
29*088332b5SXin Li
30*088332b5SXin Li #include <stddef.h>
31*088332b5SXin Li
32*088332b5SXin Li #include "lua.h"
33*088332b5SXin Li
34*088332b5SXin Li #include "lualib.h"
35*088332b5SXin Li #include "lauxlib.h"
36*088332b5SXin Li
37*088332b5SXin Li
38*088332b5SXin Li /*
39*088332b5SXin Li ** these libs are loaded by lua.c and are readily available to any Lua
40*088332b5SXin Li ** program
41*088332b5SXin Li */
42*088332b5SXin Li static const luaL_Reg loadedlibs[] = {
43*088332b5SXin Li {LUA_GNAME, luaopen_base},
44*088332b5SXin Li {LUA_LOADLIBNAME, luaopen_package},
45*088332b5SXin Li {LUA_COLIBNAME, luaopen_coroutine},
46*088332b5SXin Li {LUA_TABLIBNAME, luaopen_table},
47*088332b5SXin Li {LUA_IOLIBNAME, luaopen_io},
48*088332b5SXin Li {LUA_OSLIBNAME, luaopen_os},
49*088332b5SXin Li {LUA_STRLIBNAME, luaopen_string},
50*088332b5SXin Li {LUA_MATHLIBNAME, luaopen_math},
51*088332b5SXin Li {LUA_UTF8LIBNAME, luaopen_utf8},
52*088332b5SXin Li {LUA_DBLIBNAME, luaopen_debug},
53*088332b5SXin Li {NULL, NULL}
54*088332b5SXin Li };
55*088332b5SXin Li
56*088332b5SXin Li
luaL_openlibs(lua_State * L)57*088332b5SXin Li LUALIB_API void luaL_openlibs (lua_State *L) {
58*088332b5SXin Li const luaL_Reg *lib;
59*088332b5SXin Li /* "require" functions from 'loadedlibs' and set results to global table */
60*088332b5SXin Li for (lib = loadedlibs; lib->func; lib++) {
61*088332b5SXin Li luaL_requiref(L, lib->name, lib->func, 1);
62*088332b5SXin Li lua_pop(L, 1); /* remove lib */
63*088332b5SXin Li }
64*088332b5SXin Li }
65*088332b5SXin Li
66