diff --git a/nse_init.cc b/nse_init.cc index b836a84d7..c658d1800 100644 --- a/nse_init.cc +++ b/nse_init.cc @@ -254,21 +254,29 @@ int init_lua (lua_State *L) luaL_openlibs(L); // opens all standard libraries - lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); /* Loaded libraries */ + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); // Loaded libraries for (i = 0; i < ARRAY_LEN(libs); i++) // for each in libs - { + { lua_pushstring(L, libs[i].name); lua_pushcclosure(L, libs[i].func, 0); lua_pushvalue(L, -2); lua_call(L, 1, 1); if (lua_isnil(L, -1)) - { - lua_pushboolean(L, 1); - lua_replace(L, -2); + { + lua_getglobal(L, libs[i].name); // library? + if (!lua_istable(L, -1)) + { + lua_pop(L, 2); + lua_pushboolean(L, true); + } + else + lua_replace(L, -2); } lua_settable(L, -3); } - lua_getfield(L, -1, "debug"); // _LOADED.debug + lua_pop(L, 1); // _LOADED + + lua_getglobal(L, -1, "debug"); // _LOADED.debug lua_getfield(L, -1, "traceback"); lua_pushcclosure(L, error_function, 1); errfunc = luaL_ref(L, LUA_REGISTRYINDEX); diff --git a/nse_nmaplib.cc b/nse_nmaplib.cc index 340e20855..c261a5ae6 100644 --- a/nse_nmaplib.cc +++ b/nse_nmaplib.cc @@ -150,7 +150,9 @@ int luaopen_nmap (lua_State *L) SCRIPT_ENGINE_TRY(l_nsock_open(L)); SCRIPT_ENGINE_TRY(l_dnet_open(L)); - return 0; + lua_settop(L, 1); // just nmap lib on stack + + return 1; } /* set some port state information onto the