diff --git a/service/dbg.lua b/service/dbg.lua index 7ce43244..25b630ef 100644 --- a/service/dbg.lua +++ b/service/dbg.lua @@ -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) \ No newline at end of file diff --git a/service/launcher.lua b/service/launcher.lua index 35563f88..d672542a 100644 --- a/service/launcher.lua +++ b/service/launcher.lua @@ -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