The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
linit.cpp
Go to the documentation of this file.
1 /*
2 ** Initialization of libraries for lua.c and other clients
3 ** See Copyright Notice in lua.h
4 */
5 
6 
7 /*
8 ** If you embed Lua in your program and need to open the standard
9 ** libraries, call luaL_openlibs in your program. If you need a
10 ** different set of libraries, copy this file to your project and edit
11 ** it to suit your needs.
12 */
13 
14 
15 #define linit_c
16 #define LUA_LIB
17 
18 #include "lua.h"
19 
20 #include "lualib.h"
21 #include "lauxlib.h"
22 
23 
24 /*
25 ** these libs are loaded by lua.c and are readily available to any Lua
26 ** program
27 */
28 static const luaL_Reg loadedlibs[] = {
29  {"_G", luaopen_base},
39  {NULL, NULL}
40 };
41 
42 
43 /*
44 ** these libs are preloaded and must be required before used
45 */
46 static const luaL_Reg preloadedlibs[] = {
47  {NULL, NULL}
48 };
49 
50 
52  const luaL_Reg *lib;
53  /* call open functions from 'loadedlibs' and set results to global table */
54  for (lib = loadedlibs; lib->func; lib++) {
55  luaL_requiref(L, lib->name, lib->func, 1);
56  lua_pop(L, 1); /* remove lib */
57  }
58  /* add open functions from 'preloadedlibs' into 'package.preload' table */
59  luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD");
60  for (lib = preloadedlibs; lib->func; lib++) {
61  lua_pushcfunction(L, lib->func);
62  lua_setfield(L, -2, lib->name);
63  }
64  lua_pop(L, 1); /* remove _PRELOAD table */
65 }
66 
LUALIB_API void luaL_openlibs(lua_State *L)
Definition: linit.cpp:51
LUALIB_API void luaL_requiref(lua_State *L, const char *modname, lua_CFunction openf, int glb)
Definition: lauxlib.cpp:888
#define lua_pushcfunction(L, f)
Definition: lua.h:328
LUAMOD_API int luaopen_debug(lua_State *L)
Definition: ldblib.cpp:393
LUALIB_API int luaL_getsubtable(lua_State *L, int idx, const char *fname)
Definition: lauxlib.cpp:868
const char * name
Definition: lauxlib.h:23
#define LUA_DBLIBNAME
Definition: lualib.h:37
LUAMOD_API int luaopen_math(lua_State *L)
Definition: lmathlib.cpp:269
#define LUA_MATHLIBNAME
Definition: lualib.h:34
LUAMOD_API int luaopen_base(lua_State *L)
Definition: lbaselib.cpp:446
static const luaL_Reg loadedlibs[]
Definition: linit.cpp:28
#define lua_pop(L, n)
Definition: lua.h:322
lua_CFunction func
Definition: lauxlib.h:24
LUAMOD_API int luaopen_coroutine(lua_State *L)
Definition: lcorolib.cpp:150
LUAMOD_API int luaopen_os(lua_State *L)
Definition: loslib.cpp:318
LUAMOD_API int luaopen_io(lua_State *L)
Definition: liolib.cpp:656
LUAMOD_API int luaopen_string(lua_State *L)
Definition: lstrlib.cpp:1013
LUAMOD_API int luaopen_table(lua_State *L)
Definition: ltablib.cpp:273
LUAMOD_API int luaopen_package(lua_State *L)
Definition: loadlib.cpp:689
#define LUA_BITLIBNAME
Definition: lualib.h:31
#define LUA_STRLIBNAME
Definition: lualib.h:28
#define LUA_TABLIBNAME
Definition: lualib.h:19
#define LUA_OSLIBNAME
Definition: lualib.h:25
#define LUA_COLIBNAME
Definition: lualib.h:16
static const luaL_Reg preloadedlibs[]
Definition: linit.cpp:46
#define LUA_REGISTRYINDEX
Definition: lua.h:39
#define LUA_IOLIBNAME
Definition: lualib.h:22
LUAMOD_API int luaopen_bit32(lua_State *L)
Definition: lbitlib.cpp:207
#define LUA_LOADLIBNAME
Definition: lualib.h:40
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
Definition: lapi.cpp:752
#define LUALIB_API
Definition: luaconf.h:162