diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-07-02 08:38:13 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-07-02 08:38:13 -0300 |
| commit | 7192afafeeb1a96b3de60af90a72cd8762b09d94 (patch) | |
| tree | d1e7e061822f755c33cc497d98ea451c7e7e32e8 /ltests.c | |
| parent | a139e2e003e0b62b7d34eeda20dd2354e74885f9 (diff) | |
| download | lua-7192afafeeb1a96b3de60af90a72cd8762b09d94.tar.gz lua-7192afafeeb1a96b3de60af90a72cd8762b09d94.tar.bz2 lua-7192afafeeb1a96b3de60af90a72cd8762b09d94.zip | |
new module policy: C modules do not create globals and do not register
themselves with 'require' (let 'require' do its work); new auxiliary
functions luaL_newlib/luaL_newlibtable/luaL_setfuncs/luaL_requiref.
Old luaL_register will be deprecated.
Diffstat (limited to 'ltests.c')
| -rw-r--r-- | ltests.c | 28 |
1 files changed, 16 insertions, 12 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 2.109 2010/06/10 21:29:47 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.110 2010/06/25 12:18:10 roberto Exp roberto $ |
| 3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -841,19 +841,23 @@ static lua_State *getstate (lua_State *L) { | |||
| 841 | 841 | ||
| 842 | static int loadlib (lua_State *L) { | 842 | static int loadlib (lua_State *L) { |
| 843 | static const luaL_Reg libs[] = { | 843 | static const luaL_Reg libs[] = { |
| 844 | {"baselibopen", luaopen_base}, | 844 | {"_G", luaopen_base}, |
| 845 | {"corolibopen", luaopen_coroutine}, | 845 | {"coroutine", luaopen_coroutine}, |
| 846 | {"dblibopen", luaopen_debug}, | 846 | {"debug", luaopen_debug}, |
| 847 | {"iolibopen", luaopen_io}, | 847 | {"io", luaopen_io}, |
| 848 | {"mathlibopen", luaopen_math}, | 848 | {"math", luaopen_math}, |
| 849 | {"strlibopen", luaopen_string}, | 849 | {"string", luaopen_string}, |
| 850 | {"tablibopen", luaopen_table}, | 850 | {"table", luaopen_table}, |
| 851 | {"packageopen", luaopen_package}, | ||
| 852 | {NULL, NULL} | 851 | {NULL, NULL} |
| 853 | }; | 852 | }; |
| 854 | lua_State *L1 = getstate(L); | 853 | lua_State *L1 = getstate(L); |
| 855 | lua_pushglobaltable(L1); | 854 | int i; |
| 856 | luaL_register(L1, NULL, libs); | 855 | luaL_requiref(L1, "package", luaopen_package, 1); |
| 856 | luaL_findtable(L1, LUA_REGISTRYINDEX, "_PRELOAD"); | ||
| 857 | for (i = 0; libs[i].name; i++) { | ||
| 858 | lua_pushcfunction(L1, libs[i].func); | ||
| 859 | lua_setfield(L1, -2, libs[i].name); | ||
| 860 | } | ||
| 857 | return 0; | 861 | return 0; |
| 858 | } | 862 | } |
| 859 | 863 | ||
| @@ -874,8 +878,8 @@ static int doremote (lua_State *L) { | |||
| 874 | status = lua_pcall(L1, 0, LUA_MULTRET, 0); | 878 | status = lua_pcall(L1, 0, LUA_MULTRET, 0); |
| 875 | if (status != LUA_OK) { | 879 | if (status != LUA_OK) { |
| 876 | lua_pushnil(L); | 880 | lua_pushnil(L); |
| 877 | lua_pushinteger(L, status); | ||
| 878 | lua_pushstring(L, lua_tostring(L1, -1)); | 881 | lua_pushstring(L, lua_tostring(L1, -1)); |
| 882 | lua_pushinteger(L, status); | ||
| 879 | return 3; | 883 | return 3; |
| 880 | } | 884 | } |
| 881 | else { | 885 | else { |
