format dbg output

This commit is contained in:
云风
2012-09-15 17:03:54 +08:00
parent 7e5ab8c48c
commit 1363ee4406
2 changed files with 39 additions and 2 deletions

View File

@@ -1,12 +1,43 @@
local skynet = require "skynet"
local print_r = require "print_r"
local cmd = { ... }
local function format_table(t)
local index = {}
for k in pairs(t) do
table.insert(index, k)
end
table.sort(index)
local result = {}
for _,v in ipairs(index) do
table.insert(result, string.format("%s:%s",v,tostring(t[v])))
end
return table.concat(result,"\t")
end
local function dump_line(key, value)
if type(value) == "table" then
print(key, format_table(value))
else
print(key,tostring(value))
end
end
local function dump_list(list)
local index = {}
for k in pairs(list) do
table.insert(index, k)
end
table.sort(index)
for _,v in ipairs(index) do
dump_line(v, list[v])
end
end
skynet.start(function()
local list = skynet.call(".launcher","lua", unpack(cmd))
if list then
print_r(list)
dump_list(list)
end
skynet.exit()
end)

View File

@@ -5,6 +5,10 @@ local services = {}
local command = {}
local function handle_to_address(handle)
return tonumber("0x" .. string.sub(handle , 2))
end
function command.LIST()
local list = {}
for k,v in pairs(services) do
@@ -27,6 +31,7 @@ function command.STAT()
end
function command.INFO(handle)
handle = handle_to_address(handle)
if services[handle] == nil then
skynet.ret(skynet.pack(nil))
else
@@ -36,6 +41,7 @@ function command.INFO(handle)
end
function command.KILL(handle)
handle = handle_to_address(handle)
skynet.kill(handle)
skynet.ret( skynet.pack({ [handle] = tostring(services[handle]) }))
services[handle] = nil