From 7192afafeeb1a96b3de60af90a72cd8762b09d94 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy <roberto@inf.puc-rio.br> Date: Fri, 2 Jul 2010 08:38:13 -0300 Subject: 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. --- ltests.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'ltests.c') diff --git a/ltests.c b/ltests.c index 7bafe829..ec70a954 100644 --- a/ltests.c +++ b/ltests.c @@ -1,5 +1,5 @@ /* -** $Id: ltests.c,v 2.109 2010/06/10 21:29:47 roberto Exp roberto $ +** $Id: ltests.c,v 2.110 2010/06/25 12:18:10 roberto Exp roberto $ ** Internal Module for Debugging of the Lua Implementation ** See Copyright Notice in lua.h */ @@ -841,19 +841,23 @@ static lua_State *getstate (lua_State *L) { static int loadlib (lua_State *L) { static const luaL_Reg libs[] = { - {"baselibopen", luaopen_base}, - {"corolibopen", luaopen_coroutine}, - {"dblibopen", luaopen_debug}, - {"iolibopen", luaopen_io}, - {"mathlibopen", luaopen_math}, - {"strlibopen", luaopen_string}, - {"tablibopen", luaopen_table}, - {"packageopen", luaopen_package}, + {"_G", luaopen_base}, + {"coroutine", luaopen_coroutine}, + {"debug", luaopen_debug}, + {"io", luaopen_io}, + {"math", luaopen_math}, + {"string", luaopen_string}, + {"table", luaopen_table}, {NULL, NULL} }; lua_State *L1 = getstate(L); - lua_pushglobaltable(L1); - luaL_register(L1, NULL, libs); + int i; + luaL_requiref(L1, "package", luaopen_package, 1); + luaL_findtable(L1, LUA_REGISTRYINDEX, "_PRELOAD"); + for (i = 0; libs[i].name; i++) { + lua_pushcfunction(L1, libs[i].func); + lua_setfield(L1, -2, libs[i].name); + } return 0; } @@ -874,8 +878,8 @@ static int doremote (lua_State *L) { status = lua_pcall(L1, 0, LUA_MULTRET, 0); if (status != LUA_OK) { lua_pushnil(L); - lua_pushinteger(L, status); lua_pushstring(L, lua_tostring(L1, -1)); + lua_pushinteger(L, status); return 3; } else { -- cgit v1.2.3-55-g6feb