lua/linit.c

Go to the documentation of this file.
00001 /*
00002 ** $Id: linit.c,v 1.32 2011/04/08 19:17:36 roberto Exp $
00003 ** Initialization of libraries for lua.c and other clients
00004 ** See Copyright Notice in lua.h
00005 */
00006 
00007 
00008 /*
00009 ** If you embed Lua in your program and need to open the standard
00010 ** libraries, call luaL_openlibs in your program. If you need a
00011 ** different set of libraries, copy this file to your project and edit
00012 ** it to suit your needs.
00013 */
00014 
00015 
00016 #define linit_c
00017 #define LUA_LIB
00018 
00019 #include "lua.h"
00020 
00021 #include "lualib.h"
00022 #include "lauxlib.h"
00023 
00024 
00025 /*
00026 ** these libs are loaded by lua.c and are readily available to any Lua
00027 ** program
00028 */
00029 static const luaL_Reg loadedlibs[] = {
00030   {"_G", luaopen_base},
00031   {LUA_LOADLIBNAME, luaopen_package},
00032   {LUA_COLIBNAME, luaopen_coroutine},
00033   {LUA_TABLIBNAME, luaopen_table},
00034   {LUA_IOLIBNAME, luaopen_io},
00035   {LUA_OSLIBNAME, luaopen_os},
00036   {LUA_STRLIBNAME, luaopen_string},
00037   {LUA_BITLIBNAME, luaopen_bit32},
00038   {LUA_MATHLIBNAME, luaopen_math},
00039   {LUA_DBLIBNAME, luaopen_debug},
00040   {NULL, NULL}
00041 };
00042 
00043 
00044 /*
00045 ** these libs are preloaded and must be required before used
00046 */
00047 static const luaL_Reg preloadedlibs[] = {
00048   {NULL, NULL}
00049 };
00050 
00051 
00052 LUALIB_API void luaL_openlibs (lua_State *L) {
00053   const luaL_Reg *lib;
00054   /* call open functions from 'loadedlibs' and set results to global table */
00055   for (lib = loadedlibs; lib->func; lib++) {
00056     luaL_requiref(L, lib->name, lib->func, 1);
00057     lua_pop(L, 1);  /* remove lib */
00058   }
00059   /* add open functions from 'preloadedlibs' into 'package.preload' table */
00060   luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD");
00061   for (lib = preloadedlibs; lib->func; lib++) {
00062     lua_pushcfunction(L, lib->func);
00063     lua_setfield(L, -2, lib->name);
00064   }
00065   lua_pop(L, 1);  /* remove _PRELOAD table */
00066 }
00067 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:03 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs