/*1** $Id: linit.c $2** Initialization of libraries for lua.c and other clients3** See Copyright Notice in lua.h4*/567#define linit_c8#define LUA_LIB910/*11** If you embed Lua in your program and need to open the standard12** libraries, call luaL_openlibs in your program. If you need a13** different set of libraries, copy this file to your project and edit14** it to suit your needs.15**16** You can also *preload* libraries, so that a later 'require' can17** open the library, which is already linked to the application.18** For that, do the following code:19**20** luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);21** lua_pushcfunction(L, luaopen_modname);22** lua_setfield(L, -2, modname);23** lua_pop(L, 1); // remove PRELOAD table24*/2526#include "lprefix.h"272829#include <stddef.h>3031#include "lua.h"3233#include "lualib.h"34#include "lauxlib.h"353637/*38** these libs are loaded by lua.c and are readily available to any Lua39** program40*/41static const luaL_Reg loadedlibs[] = {42{LUA_GNAME, luaopen_base},43{LUA_LOADLIBNAME, luaopen_package},44{LUA_COLIBNAME, luaopen_coroutine},45{LUA_TABLIBNAME, luaopen_table},46{LUA_IOLIBNAME, luaopen_io},47{LUA_OSLIBNAME, luaopen_os},48{LUA_STRLIBNAME, luaopen_string},49{LUA_MATHLIBNAME, luaopen_math},50{LUA_UTF8LIBNAME, luaopen_utf8},51{LUA_DBLIBNAME, luaopen_debug},52{NULL, NULL}53};545556LUALIB_API void luaL_openlibs (lua_State *L) {57const luaL_Reg *lib;58/* "require" functions from 'loadedlibs' and set results to global table */59for (lib = loadedlibs; lib->func; lib++) {60luaL_requiref(L, lib->name, lib->func, 1);61lua_pop(L, 1); /* remove lib */62}63}64656667