1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-26 01:19:03 +00:00

Updated library handling in nse_init, and made

nmap library properly return its library table.
This commit is contained in:
batrick
2008-06-21 13:28:03 +00:00
parent ac5138b975
commit ac52d97c25
2 changed files with 17 additions and 7 deletions

View File

@@ -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);

View File

@@ -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