1 /* $NetBSD: linit.c,v 1.4 2015/02/02 14:03:05 lneto Exp $ */
4 ** Id: linit.c,v 1.38 2015/01/05 13:48:33 roberto Exp
5 ** Initialization of libraries for lua.c and other clients
6 ** See Copyright Notice in lua.h
14 ** If you embed Lua in your program and need to open the standard
15 ** libraries, call luaL_openlibs in your program. If you need a
16 ** different set of libraries, copy this file to your project and edit
17 ** it to suit your needs.
19 ** You can also *preload* libraries, so that a later 'require' can
20 ** open the library, which is already linked to the application.
21 ** For that, do the following code:
23 ** luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD");
24 ** lua_pushcfunction(L, luaopen_modname);
25 ** lua_setfield(L, -2, modname);
26 ** lua_pop(L, 1); // remove _PRELOAD table
43 ** these libs are loaded by lua.c and are readily available to any Lua
46 static const luaL_Reg loadedlibs
[] = {
49 {LUA_LOADLIBNAME
, luaopen_package
},
51 {LUA_COLIBNAME
, luaopen_coroutine
},
52 {LUA_TABLIBNAME
, luaopen_table
},
54 {LUA_IOLIBNAME
, luaopen_io
},
55 {LUA_OSLIBNAME
, luaopen_os
},
57 {LUA_STRLIBNAME
, luaopen_string
},
59 {LUA_MATHLIBNAME
, luaopen_math
},
61 {LUA_UTF8LIBNAME
, luaopen_utf8
},
62 {LUA_DBLIBNAME
, luaopen_debug
},
63 #if defined(LUA_COMPAT_BITLIB)
64 {LUA_BITLIBNAME
, luaopen_bit32
},
70 LUALIB_API
void luaL_openlibs (lua_State
*L
) {
72 /* "require" functions from 'loadedlibs' and set results to global table */
73 for (lib
= loadedlibs
; lib
->func
; lib
++) {
74 luaL_requiref(L
, lib
->name
, lib
->func
, 1);
75 lua_pop(L
, 1); /* remove lib */