new protocol to open standard libraries
This commit is contained in:
17
linit.c
17
linit.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: linit.c,v 1.9 2005/02/18 12:40:02 roberto Exp roberto $
|
||||
** $Id: linit.c,v 1.10 2005/03/08 13:37:55 roberto Exp roberto $
|
||||
** Initialization of libraries for lua.c
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -22,22 +22,17 @@ static const luaL_reg lualibs[] = {
|
||||
{LUA_STRLIBNAME, luaopen_string},
|
||||
{LUA_MATHLIBNAME, luaopen_math},
|
||||
{LUA_DBLIBNAME, luaopen_debug},
|
||||
{"", luaopen_loadlib},
|
||||
{LUA_LOADLIBNAME, luaopen_loadlib},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
LUALIB_API int luaopen_stdlibs (lua_State *L) {
|
||||
LUALIB_API void luaL_openlibs (lua_State *L) {
|
||||
const luaL_reg *lib = lualibs;
|
||||
int t = lua_gettop(L);
|
||||
lua_pushvalue(L, LUA_ENVIRONINDEX); /* save original environment */
|
||||
for (; lib->func; lib++) {
|
||||
lib->func(L); /* open library */
|
||||
lua_settop(L, t + 1); /* discard any results */
|
||||
lua_pushvalue(L, -1);
|
||||
lua_replace(L, LUA_ENVIRONINDEX); /* restore environment */
|
||||
lua_pushcfunction(L, lib->func);
|
||||
lua_pushstring(L, lib->name);
|
||||
lua_call(L, 1, 0);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user