1254721Semaste/* 2254721Semaste** $Id: linit.c,v 1.39.1.1 2017/04/19 17:20:42 roberto Exp $ 3353358Sdim** Initialization of libraries for lua.c and other clients 4353358Sdim** See Copyright Notice in lua.h 5353358Sdim*/ 6254721Semaste 7254721Semaste 8254721Semaste#define linit_c 9254721Semaste#define LUA_LIB 10254721Semaste 11254721Semaste/* 12276479Sdim** If you embed Lua in your program and need to open the standard 13321369Sdim** libraries, call luaL_openlibs in your program. If you need a 14321369Sdim** different set of libraries, copy this file to your project and edit 15344779Sdim** it to suit your needs. 16344779Sdim** 17321369Sdim** You can also *preload* libraries, so that a later 'require' can 18254721Semaste** open the library, which is already linked to the application. 19254721Semaste** For that, do the following code: 20254721Semaste** 21254721Semaste** luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); 22296417Sdim** lua_pushcfunction(L, luaopen_modname); 23341825Sdim** lua_setfield(L, -2, modname); 24254721Semaste** lua_pop(L, 1); // remove PRELOAD table 25353358Sdim*/ 26353358Sdim 27254721Semaste#include "lprefix.h" 28254721Semaste 29288943Sdim 30254721Semaste#include <stddef.h> 31254721Semaste 32314564Sdim#include "lua.h" 33314564Sdim 34360784Sdim#include "lualib.h" 35360784Sdim#include "lauxlib.h" 36314564Sdim 37360784Sdim 38360784Sdim/* 39341825Sdim** these libs are loaded by lua.c and are readily available to any Lua 40341825Sdim** program 41341825Sdim*/ 42314564Sdimstatic const luaL_Reg loadedlibs[] = { 43254721Semaste {"_G", luaopen_base}, 44314564Sdim {LUA_LOADLIBNAME, luaopen_package}, 45314564Sdim {LUA_COLIBNAME, luaopen_coroutine}, 46314564Sdim {LUA_TABLIBNAME, luaopen_table}, 47314564Sdim {LUA_IOLIBNAME, luaopen_io}, 48314564Sdim {LUA_OSLIBNAME, luaopen_os}, 49254721Semaste {LUA_STRLIBNAME, luaopen_string}, 50254721Semaste {LUA_MATHLIBNAME, luaopen_math}, 51254721Semaste {LUA_UTF8LIBNAME, luaopen_utf8}, 52314564Sdim {LUA_DBLIBNAME, luaopen_debug}, 53254721Semaste#if defined(LUA_COMPAT_BITLIB) 54314564Sdim {LUA_BITLIBNAME, luaopen_bit32}, 55314564Sdim#endif 56254721Semaste {NULL, NULL} 57254721Semaste}; 58314564Sdim 59314564Sdim 60314564SdimLUALIB_API void luaL_openlibs (lua_State *L) { 61314564Sdim const luaL_Reg *lib; 62254721Semaste /* "require" functions from 'loadedlibs' and set results to global table */ 63254721Semaste for (lib = loadedlibs; lib->func; lib++) { 64314564Sdim luaL_requiref(L, lib->name, lib->func, 1); 65314564Sdim lua_pop(L, 1); /* remove lib */ 66254721Semaste } 67254721Semaste} 68254721Semaste 69314564Sdim