mirror of https://github.com/rusefi/lua.git
new protocol to open standard libraries
This commit is contained in:
parent
2873d4efff
commit
04f657c7f8
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
|
** Initialization of libraries for lua.c
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -22,22 +22,17 @@ static const luaL_reg lualibs[] = {
|
||||||
{LUA_STRLIBNAME, luaopen_string},
|
{LUA_STRLIBNAME, luaopen_string},
|
||||||
{LUA_MATHLIBNAME, luaopen_math},
|
{LUA_MATHLIBNAME, luaopen_math},
|
||||||
{LUA_DBLIBNAME, luaopen_debug},
|
{LUA_DBLIBNAME, luaopen_debug},
|
||||||
{"", luaopen_loadlib},
|
{LUA_LOADLIBNAME, luaopen_loadlib},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
LUALIB_API int luaopen_stdlibs (lua_State *L) {
|
LUALIB_API void luaL_openlibs (lua_State *L) {
|
||||||
const luaL_reg *lib = lualibs;
|
const luaL_reg *lib = lualibs;
|
||||||
int t = lua_gettop(L);
|
|
||||||
lua_pushvalue(L, LUA_ENVIRONINDEX); /* save original environment */
|
|
||||||
for (; lib->func; lib++) {
|
for (; lib->func; lib++) {
|
||||||
lib->func(L); /* open library */
|
lua_pushcfunction(L, lib->func);
|
||||||
lua_settop(L, t + 1); /* discard any results */
|
lua_pushstring(L, lib->name);
|
||||||
lua_pushvalue(L, -1);
|
lua_call(L, 1, 0);
|
||||||
lua_replace(L, LUA_ENVIRONINDEX); /* restore environment */
|
|
||||||
}
|
}
|
||||||
lua_pop(L, 1);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: loadlib.c,v 1.24 2005/03/29 16:20:48 roberto Exp roberto $
|
** $Id: loadlib.c,v 1.25 2005/03/30 19:50:29 roberto Exp roberto $
|
||||||
** Dynamic library loader for Lua
|
** Dynamic library loader for Lua
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
**
|
**
|
||||||
|
@ -474,7 +474,7 @@ LUALIB_API int luaopen_loadlib (lua_State *L) {
|
||||||
/* create `package' table */
|
/* create `package' table */
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
lua_pushvalue(L, -1);
|
lua_pushvalue(L, -1);
|
||||||
lua_setglobal(L, "package");
|
lua_setglobal(L, LUA_LOADLIBNAME);
|
||||||
lua_pushvalue(L, -1);
|
lua_pushvalue(L, -1);
|
||||||
lua_setfield(L, LUA_REGISTRYINDEX, "_PACKAGE");
|
lua_setfield(L, LUA_REGISTRYINDEX, "_PACKAGE");
|
||||||
lua_pushvalue(L, -1);
|
lua_pushvalue(L, -1);
|
||||||
|
|
4
ltests.h
4
ltests.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: ltests.h,v 2.11 2005/01/10 16:31:30 roberto Exp roberto $
|
** $Id: ltests.h,v 2.12 2005/03/18 18:55:45 roberto Exp roberto $
|
||||||
** Internal Header for Debugging of the Lua Implementation
|
** Internal Header for Debugging of the Lua Implementation
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -67,7 +67,7 @@ extern int islocked;
|
||||||
int luaB_opentests (lua_State *L);
|
int luaB_opentests (lua_State *L);
|
||||||
|
|
||||||
#ifdef lua_c
|
#ifdef lua_c
|
||||||
#define luaopen_stdlibs(L) { (luaopen_stdlibs)(L); luaB_opentests(L); }
|
#define luaL_openlibs(L) { (luaL_openlibs)(L); luaB_opentests(L); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
4
lua.c
4
lua.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lua.c,v 1.140 2005/03/30 19:50:29 roberto Exp roberto $
|
** $Id: lua.c,v 1.141 2005/04/11 18:01:35 roberto Exp roberto $
|
||||||
** Lua stand-alone interpreter
|
** Lua stand-alone interpreter
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -343,7 +343,7 @@ static int pmain (lua_State *L) {
|
||||||
int interactive = 1;
|
int interactive = 1;
|
||||||
if (s->argv[0] && s->argv[0][0]) progname = s->argv[0];
|
if (s->argv[0] && s->argv[0][0]) progname = s->argv[0];
|
||||||
globalL = L;
|
globalL = L;
|
||||||
luaopen_stdlibs(L); /* open libraries */
|
luaL_openlibs(L); /* open libraries */
|
||||||
status = handle_luainit(L);
|
status = handle_luainit(L);
|
||||||
if (status == 0) {
|
if (status == 0) {
|
||||||
status = handle_argv(L, s->argc, s->argv, &interactive);
|
status = handle_argv(L, s->argc, s->argv, &interactive);
|
||||||
|
|
6
lualib.h
6
lualib.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lualib.h,v 1.32 2004/07/09 15:47:48 roberto Exp roberto $
|
** $Id: lualib.h,v 1.33 2005/01/10 16:31:30 roberto Exp roberto $
|
||||||
** Lua standard libraries
|
** Lua standard libraries
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -36,12 +36,12 @@ LUALIB_API int (luaopen_math) (lua_State *L);
|
||||||
#define LUA_DBLIBNAME "debug"
|
#define LUA_DBLIBNAME "debug"
|
||||||
LUALIB_API int (luaopen_debug) (lua_State *L);
|
LUALIB_API int (luaopen_debug) (lua_State *L);
|
||||||
|
|
||||||
|
#define LUA_LOADLIBNAME "package"
|
||||||
LUALIB_API int (luaopen_loadlib) (lua_State *L);
|
LUALIB_API int (luaopen_loadlib) (lua_State *L);
|
||||||
|
|
||||||
|
|
||||||
/* open all previous libraries */
|
/* open all previous libraries */
|
||||||
LUALIB_API int (luaopen_stdlibs) (lua_State *L);
|
LUALIB_API void (luaL_openlibs) (lua_State *L);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue