source: trunk/src/lua/linit.c @ 2542

Last change on this file since 2542 was 2542, checked in by sam, 10 years ago

lua: compilation fixes for non-quite-POSIX platforms.

File size: 1.7 KB
Line 
1/*
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
5*/
6
7#if defined HAVE_CONFIG_H // LOL BEGIN
8#   include "config.h"
9#endif // LOL END
10
11/*
12** If you embed Lua in your program and need to open the standard
13** libraries, call luaL_openlibs in your program. If you need a
14** different set of libraries, copy this file to your project and edit
15** it to suit your needs.
16*/
17
18
19#define linit_c
20#define LUA_LIB
21
22#include "lua.h"
23
24#include "lualib.h"
25#include "lauxlib.h"
26
27
28/*
29** these libs are loaded by lua.c and are readily available to any Lua
30** program
31*/
32static const luaL_Reg loadedlibs[] = {
33  {"_G", luaopen_base},
34  {LUA_LOADLIBNAME, luaopen_package},
35  {LUA_COLIBNAME, luaopen_coroutine},
36  {LUA_TABLIBNAME, luaopen_table},
37  {LUA_IOLIBNAME, luaopen_io},
38  {LUA_OSLIBNAME, luaopen_os},
39  {LUA_STRLIBNAME, luaopen_string},
40  {LUA_BITLIBNAME, luaopen_bit32},
41  {LUA_MATHLIBNAME, luaopen_math},
42  {LUA_DBLIBNAME, luaopen_debug},
43  {NULL, NULL}
44};
45
46
47/*
48** these libs are preloaded and must be required before used
49*/
50static const luaL_Reg preloadedlibs[] = {
51  {NULL, NULL}
52};
53
54
55LUALIB_API void luaL_openlibs (lua_State *L) {
56  const luaL_Reg *lib;
57  /* call open functions from 'loadedlibs' and set results to global table */
58  for (lib = loadedlibs; lib->func; lib++) {
59    luaL_requiref(L, lib->name, lib->func, 1);
60    lua_pop(L, 1);  /* remove lib */
61  }
62  /* add open functions from 'preloadedlibs' into 'package.preload' table */
63  luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD");
64  for (lib = preloadedlibs; lib->func; lib++) {
65    lua_pushcfunction(L, lib->func);
66    lua_setfield(L, -2, lib->name);
67  }
68  lua_pop(L, 1);  /* remove _PRELOAD table */
69}
70
Note: See TracBrowser for help on using the repository browser.