diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-04-13 14:24:20 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-04-13 14:24:20 -0300 |
| commit | 04f657c7f892072d7cdc021e9e2635acc086f898 (patch) | |
| tree | f5cd7c82ae0152a1b252511f85b58296590eca04 | |
| parent | 2873d4efff18e972a94a6d20c231b0ac062bc4ca (diff) | |
| download | lua-04f657c7f892072d7cdc021e9e2635acc086f898.tar.gz lua-04f657c7f892072d7cdc021e9e2635acc086f898.tar.bz2 lua-04f657c7f892072d7cdc021e9e2635acc086f898.zip | |
new protocol to open standard libraries
| -rw-r--r-- | linit.c | 17 | ||||
| -rw-r--r-- | loadlib.c | 4 | ||||
| -rw-r--r-- | ltests.h | 4 | ||||
| -rw-r--r-- | lua.c | 4 | ||||
| -rw-r--r-- | lualib.h | 6 |
5 files changed, 15 insertions, 20 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: linit.c,v 1.9 2005/02/18 12:40:02 roberto Exp roberto $ | 2 | ** $Id: linit.c,v 1.10 2005/03/08 13:37:55 roberto Exp roberto $ |
| 3 | ** Initialization of libraries for lua.c | 3 | ** Initialization of libraries for lua.c |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -22,22 +22,17 @@ static const luaL_reg lualibs[] = { | |||
| 22 | {LUA_STRLIBNAME, luaopen_string}, | 22 | {LUA_STRLIBNAME, luaopen_string}, |
| 23 | {LUA_MATHLIBNAME, luaopen_math}, | 23 | {LUA_MATHLIBNAME, luaopen_math}, |
| 24 | {LUA_DBLIBNAME, luaopen_debug}, | 24 | {LUA_DBLIBNAME, luaopen_debug}, |
| 25 | {"", luaopen_loadlib}, | 25 | {LUA_LOADLIBNAME, luaopen_loadlib}, |
| 26 | {NULL, NULL} | 26 | {NULL, NULL} |
| 27 | }; | 27 | }; |
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | LUALIB_API int luaopen_stdlibs (lua_State *L) { | 30 | LUALIB_API void luaL_openlibs (lua_State *L) { |
| 31 | const luaL_reg *lib = lualibs; | 31 | const luaL_reg *lib = lualibs; |
| 32 | int t = lua_gettop(L); | ||
| 33 | lua_pushvalue(L, LUA_ENVIRONINDEX); /* save original environment */ | ||
| 34 | for (; lib->func; lib++) { | 32 | for (; lib->func; lib++) { |
| 35 | lib->func(L); /* open library */ | 33 | lua_pushcfunction(L, lib->func); |
| 36 | lua_settop(L, t + 1); /* discard any results */ | 34 | lua_pushstring(L, lib->name); |
| 37 | lua_pushvalue(L, -1); | 35 | lua_call(L, 1, 0); |
| 38 | lua_replace(L, LUA_ENVIRONINDEX); /* restore environment */ | ||
| 39 | } | 36 | } |
| 40 | lua_pop(L, 1); | ||
| 41 | return 0; | ||
| 42 | } | 37 | } |
| 43 | 38 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: loadlib.c,v 1.24 2005/03/29 16:20:48 roberto Exp roberto $ | 2 | ** $Id: loadlib.c,v 1.25 2005/03/30 19:50:29 roberto Exp roberto $ |
| 3 | ** Dynamic library loader for Lua | 3 | ** Dynamic library loader for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | ** | 5 | ** |
| @@ -474,7 +474,7 @@ LUALIB_API int luaopen_loadlib (lua_State *L) { | |||
| 474 | /* create `package' table */ | 474 | /* create `package' table */ |
| 475 | lua_newtable(L); | 475 | lua_newtable(L); |
| 476 | lua_pushvalue(L, -1); | 476 | lua_pushvalue(L, -1); |
| 477 | lua_setglobal(L, "package"); | 477 | lua_setglobal(L, LUA_LOADLIBNAME); |
| 478 | lua_pushvalue(L, -1); | 478 | lua_pushvalue(L, -1); |
| 479 | lua_setfield(L, LUA_REGISTRYINDEX, "_PACKAGE"); | 479 | lua_setfield(L, LUA_REGISTRYINDEX, "_PACKAGE"); |
| 480 | lua_pushvalue(L, -1); | 480 | lua_pushvalue(L, -1); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.h,v 2.11 2005/01/10 16:31:30 roberto Exp roberto $ | 2 | ** $Id: ltests.h,v 2.12 2005/03/18 18:55:45 roberto Exp roberto $ |
| 3 | ** Internal Header for Debugging of the Lua Implementation | 3 | ** Internal Header for Debugging of the Lua Implementation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -67,7 +67,7 @@ extern int islocked; | |||
| 67 | int luaB_opentests (lua_State *L); | 67 | int luaB_opentests (lua_State *L); |
| 68 | 68 | ||
| 69 | #ifdef lua_c | 69 | #ifdef lua_c |
| 70 | #define luaopen_stdlibs(L) { (luaopen_stdlibs)(L); luaB_opentests(L); } | 70 | #define luaL_openlibs(L) { (luaL_openlibs)(L); luaB_opentests(L); } |
| 71 | #endif | 71 | #endif |
| 72 | 72 | ||
| 73 | 73 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.c,v 1.140 2005/03/30 19:50:29 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.141 2005/04/11 18:01:35 roberto Exp roberto $ |
| 3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -343,7 +343,7 @@ static int pmain (lua_State *L) { | |||
| 343 | int interactive = 1; | 343 | int interactive = 1; |
| 344 | if (s->argv[0] && s->argv[0][0]) progname = s->argv[0]; | 344 | if (s->argv[0] && s->argv[0][0]) progname = s->argv[0]; |
| 345 | globalL = L; | 345 | globalL = L; |
| 346 | luaopen_stdlibs(L); /* open libraries */ | 346 | luaL_openlibs(L); /* open libraries */ |
| 347 | status = handle_luainit(L); | 347 | status = handle_luainit(L); |
| 348 | if (status == 0) { | 348 | if (status == 0) { |
| 349 | status = handle_argv(L, s->argc, s->argv, &interactive); | 349 | status = handle_argv(L, s->argc, s->argv, &interactive); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lualib.h,v 1.32 2004/07/09 15:47:48 roberto Exp roberto $ | 2 | ** $Id: lualib.h,v 1.33 2005/01/10 16:31:30 roberto Exp roberto $ |
| 3 | ** Lua standard libraries | 3 | ** Lua standard libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -36,12 +36,12 @@ LUALIB_API int (luaopen_math) (lua_State *L); | |||
| 36 | #define LUA_DBLIBNAME "debug" | 36 | #define LUA_DBLIBNAME "debug" |
| 37 | LUALIB_API int (luaopen_debug) (lua_State *L); | 37 | LUALIB_API int (luaopen_debug) (lua_State *L); |
| 38 | 38 | ||
| 39 | 39 | #define LUA_LOADLIBNAME "package" | |
| 40 | LUALIB_API int (luaopen_loadlib) (lua_State *L); | 40 | LUALIB_API int (luaopen_loadlib) (lua_State *L); |
| 41 | 41 | ||
| 42 | 42 | ||
| 43 | /* open all previous libraries */ | 43 | /* open all previous libraries */ |
| 44 | LUALIB_API int (luaopen_stdlibs) (lua_State *L); | 44 | LUALIB_API void (luaL_openlibs) (lua_State *L); |
| 45 | 45 | ||
| 46 | 46 | ||
| 47 | #endif | 47 | #endif |
