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:
20
nse_init.cc
20
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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user