1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

Large recode of nse_init.cc

Now does most of it's work through Lua:

From Nmap-dev: "Many of the changes consist of changing how Nmap interfaces
with Lua that were sometimes awkward or inflexible. Most of the functions 
have been made to be callable directly by Lua which offers many technical
advantages: stack management is alleviated, errors are handled cleanly and
are more descriptive, and there is increased reusability."

Additionally:
   -- Moved all lua_State * symbols from "l" to "L". This is to maintain
      consistency with other Lua libraries (convention) and to make our macros portable.
   -- Moved file system manipulation over to nse_fs.cc (from nse_init.cc)
This commit is contained in:
batrick
2008-05-31 02:39:27 +00:00
parent 742ff67100
commit d0bc640db8
14 changed files with 1563 additions and 1388 deletions

View File

@@ -1,63 +1,63 @@
#include "nse_debug.h"
#include "output.h"
void l_dumpStack(lua_State* l) {
int stack_height = lua_gettop(l);
void l_dumpStack(lua_State *L) {
int stack_height = lua_gettop(L);
int i;
log_write(LOG_PLAIN, "-== Stack Dump Begin ==-\n");
for(i = -1; i >= 0 - stack_height; i--) {
log_write(LOG_PLAIN, "%d: ", i);
l_dumpValue(l, i);
l_dumpValue(L, i);
}
log_write(LOG_PLAIN, "-== Stack Dump End ==-\n");
}
void l_dumpValue(lua_State* l, int i) {
switch (lua_type(l, i))
void l_dumpValue(lua_State *L, int i) {
switch (lua_type(L, i))
{
case LUA_TTABLE:
l_dumpTable(l, i);
l_dumpTable(L, i);
break;
case LUA_TFUNCTION:
l_dumpFunction(l, i);
l_dumpFunction(L, i);
break;
case LUA_TSTRING:
log_write(LOG_PLAIN, "string '%s'\n", lua_tostring(l, i));
log_write(LOG_PLAIN, "string '%s'\n", lua_tostring(L, i));
break;
case LUA_TBOOLEAN:
log_write(LOG_PLAIN, "boolean: %s\n",
lua_toboolean(l, i) ? "true" : "false");
lua_toboolean(L, i) ? "true" : "false");
break;
case LUA_TNUMBER:
log_write(LOG_PLAIN, "number: %g\n", lua_tonumber(l, i));
log_write(LOG_PLAIN, "number: %g\n", lua_tonumber(L, i));
break;
default:
log_write(LOG_PLAIN, "%s\n", lua_typename(l, lua_type(l, i)));
log_write(LOG_PLAIN, "%s\n", lua_typename(L, lua_type(L, i)));
}
}
void l_dumpTable(lua_State *l, int index) {
void l_dumpTable(lua_State *L, int index) {
log_write(LOG_PLAIN, "table\n");
lua_pushnil(l);
lua_pushnil(L);
if (index<0) --index;
while(lua_next(l, index) != 0)
while(lua_next(L, index) != 0)
{
l_dumpValue(l, -2);
l_dumpValue(l, -1);
lua_pop(l, 1);
l_dumpValue(L, -2);
l_dumpValue(L, -1);
lua_pop(L, 1);
}
}
void l_dumpFunction(lua_State* l, int index) {
void l_dumpFunction(lua_State *L, int index) {
// lua_Debug ar;
log_write(LOG_PLAIN, "function\n");
// lua_pushvalue(l, index);
// lua_getinfo(l, ">n", &ar);
// lua_pushvalue(L, index);
// lua_getinfo(L, ">n", &ar);
//
// log_write(LOG_PLAIN, "\tname: %s %s\n", ar.namewhat, ar.name);
fflush(stdout);