mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
Lua 5.2 upgrade [1] for NSE.
[1] http://seclists.org/nmap-dev/2012/q2/34
This commit is contained in:
35
nse_debug.cc
35
nse_debug.cc
@@ -10,50 +10,49 @@ extern "C" {
|
||||
|
||||
/* Print a Lua table. depth_limit is the limit on recursive printing of
|
||||
subtables. */
|
||||
static void table_dump (lua_State *L, int i, int depth_limit)
|
||||
static void table_dump (lua_State *L, int idx, int depth_limit)
|
||||
{
|
||||
assert(lua_type(L, i) == LUA_TTABLE);
|
||||
idx = lua_absindex(L, idx);
|
||||
assert(lua_type(L, idx) == LUA_TTABLE);
|
||||
printf("{ ");
|
||||
lua_pushvalue(L, i);
|
||||
lua_pushnil(L);
|
||||
while (lua_next(L, -2) != 0) {
|
||||
for (lua_pushnil(L); lua_next(L, idx); lua_pop(L, 1))
|
||||
{
|
||||
value_dump(L, -2, depth_limit - 1);
|
||||
printf(" = ");
|
||||
value_dump(L, -1, depth_limit - 1);
|
||||
printf(", ");
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
printf("}");
|
||||
}
|
||||
|
||||
/* Print a Lua value. depth_limit controls the depth to which tables will be
|
||||
printed recursively (0 for no recursion). */
|
||||
void value_dump (lua_State *L, int i, int depth_limit)
|
||||
void value_dump (lua_State *L, int idx, int depth_limit)
|
||||
{
|
||||
int t = lua_type(L, i);
|
||||
idx = lua_absindex(L, idx);
|
||||
int t = lua_type(L, idx);
|
||||
switch (t)
|
||||
{
|
||||
case LUA_TSTRING: /* strings */
|
||||
printf("'%s'", lua_tostring(L, i));
|
||||
printf("'%s'", lua_tostring(L, idx));
|
||||
break;
|
||||
case LUA_TBOOLEAN: /* booleans */
|
||||
printf(lua_toboolean(L, i) ? "true" : "false");
|
||||
printf(lua_toboolean(L, idx) ? "true" : "false");
|
||||
break;
|
||||
case LUA_TNUMBER: /* numbers */
|
||||
printf("%g", lua_tonumber(L, i));
|
||||
printf("%g", lua_tonumber(L, idx));
|
||||
break;
|
||||
case LUA_TTABLE:
|
||||
if (depth_limit > 0)
|
||||
table_dump(L, i, depth_limit);
|
||||
table_dump(L, idx, depth_limit);
|
||||
else
|
||||
printf("table: %p", lua_topointer(L, i));
|
||||
printf("table: %p", lua_topointer(L, idx));
|
||||
break;
|
||||
case LUA_TTHREAD:
|
||||
case LUA_TFUNCTION:
|
||||
case LUA_TUSERDATA:
|
||||
case LUA_TLIGHTUSERDATA:
|
||||
printf("%s: %p", lua_typename(L, t), lua_topointer(L, i));
|
||||
printf("%s: %p", lua_typename(L, t), lua_topointer(L, idx));
|
||||
break;
|
||||
default: /* other values */
|
||||
printf("%s", lua_typename(L, t));
|
||||
@@ -83,7 +82,9 @@ void lua_state_dump (lua_State *L)
|
||||
stack_dump(L);
|
||||
|
||||
printf("=== GLOBALS\n");
|
||||
table_dump(L, LUA_GLOBALSINDEX, 0);
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS);
|
||||
table_dump(L, -1, 0);
|
||||
lua_pop(L, 1); /* LUA_RIDX_GLOBALS */
|
||||
printf("\n");
|
||||
|
||||
printf("=== REGISTRY\n");
|
||||
@@ -94,8 +95,8 @@ void lua_state_dump (lua_State *L)
|
||||
lua_getglobal(L, "nmap");
|
||||
lua_getfield(L, -1, "registry");
|
||||
table_dump(L, -1, 1);
|
||||
printf("\n");
|
||||
lua_pop(L, 2);
|
||||
printf("\n");
|
||||
|
||||
assert(lua_gettop(L) == top);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user