3 ** $Id: linit.c,v 1.39.1.1 2017/04/19 17:20:42 roberto Exp $
4 ** Initialization of libraries for lua.c and other clients
5 ** See Copyright Notice in lua.h
13 ** If you embed Lua in your program and need to open the standard
14 ** libraries, call luaL_openlibs in your program. If you need a
15 ** different set of libraries, copy this file to your project and edit
16 ** it to suit your needs.
18 ** You can also *preload* libraries, so that a later 'require' can
19 ** open the library, which is already linked to the application.
20 ** For that, do the following code:
22 ** luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);
23 ** lua_pushcfunction(L, luaopen_modname);
24 ** lua_setfield(L, -2, modname);
25 ** lua_pop(L, 1); // remove PRELOAD table
41 ** these libs are loaded by lua.c and are readily available to any Lua
44 static const luaL_Reg loadedlibs[] = {
46 {LUA_LOADLIBNAME, luaopen_package},
47 {LUA_COLIBNAME, luaopen_coroutine},
48 {LUA_TABLIBNAME, luaopen_table},
49 {LUA_IOLIBNAME, luaopen_io},
50 {LUA_OSLIBNAME, luaopen_os},
51 {LUA_STRLIBNAME, luaopen_string},
52 {LUA_MATHLIBNAME, luaopen_math},
53 {LUA_UTF8LIBNAME, luaopen_utf8},
54 {LUA_DBLIBNAME, luaopen_debug},
55 #if defined(LUA_COMPAT_BITLIB)
56 {LUA_BITLIBNAME, luaopen_bit32},
58 /* FreeBSD Extensions */
60 {"posix.unistd", luaopen_posix_unistd},
65 LUALIB_API void luaL_openlibs (lua_State *L) {
67 /* "require" functions from 'loadedlibs' and set results to global table */
68 for (lib = loadedlibs; lib->func; lib++) {
69 luaL_requiref(L, lib->name, lib->func, 1);
70 lua_pop(L, 1); /* remove lib */