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 /linit.c | |
| parent | 2873d4efff18e972a94a6d20c231b0ac062bc4ca (diff) | |
| download | lua-04f657c7f892072d7cdc021e9e2635acc086f898.tar.gz lua-04f657c7f892072d7cdc021e9e2635acc086f898.tar.bz2 lua-04f657c7f892072d7cdc021e9e2635acc086f898.zip | |
new protocol to open standard libraries
Diffstat (limited to 'linit.c')
| -rw-r--r-- | linit.c | 17 |
1 files changed, 6 insertions, 11 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 | ||
