2 ** $Id: linit.c,v 1.32 2011/04/08 19:17:36 roberto Exp $
3 ** Initialization of libraries for lua.c and other clients
4 ** See Copyright Notice in lua.h
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.
26 ** these libs are loaded by lua.c and are readily available to any Lua
29 static const luaL_Reg loadedlibs
[] = {
31 {LUA_LOADLIBNAME
, luaopen_package
},
32 {LUA_COLIBNAME
, luaopen_coroutine
},
33 {LUA_TABLIBNAME
, luaopen_table
},
34 {LUA_IOLIBNAME
, luaopen_io
},
35 {LUA_OSLIBNAME
, luaopen_os
},
36 {LUA_STRLIBNAME
, luaopen_string
},
37 {LUA_BITLIBNAME
, luaopen_bit32
},
38 {LUA_MATHLIBNAME
, luaopen_math
},
39 {LUA_DBLIBNAME
, luaopen_debug
},
45 ** these libs are preloaded and must be required before used
47 static const luaL_Reg preloadedlibs
[] = {
52 LUALIB_API
void luaL_openlibs (lua_State
*L
) {
54 /* call open functions from 'loadedlibs' and set results to global table */
55 for (lib
= loadedlibs
; lib
->func
; lib
++) {
56 luaL_requiref(L
, lib
->name
, lib
->func
, 1);
57 lua_pop(L
, 1); /* remove lib */
59 /* add open functions from 'preloadedlibs' into 'package.preload' table */
60 luaL_getsubtable(L
, LUA_REGISTRYINDEX
, "_PRELOAD");
61 for (lib
= preloadedlibs
; lib
->func
; lib
++) {
62 lua_pushcfunction(L
, lib
->func
);
63 lua_setfield(L
, -2, lib
->name
);
65 lua_pop(L
, 1); /* remove _PRELOAD table */