move lualib/snax_* to lualib/snax/

This commit is contained in:
Cloud Wu
2014-04-29 17:05:27 +08:00
parent f161dbb0ea
commit a4a21bd793
7 changed files with 124 additions and 119 deletions

View File

@@ -399,7 +399,7 @@ local function raw_dispatch_message(prototype, msg, sz, session, source, ...)
session_coroutine_address[co] = source
suspend(co, coroutine.resume(co, session,source, p.unpack(msg,sz, ...)))
else
unknown_request(session, source, msg, sz)
unknown_request(session, source, msg, sz)
end
end
end
@@ -426,8 +426,7 @@ local function dispatch_message(...)
end
function skynet.newservice(name, ...)
local param = table.concat({"snlua", name, ...}, " ")
local handle = skynet.call(".launcher", "text" , param)
local handle = skynet.tostring(skynet.rawcall(".launcher", "lua" , skynet.pack("LAUNCH", "snlua", name, ...)))
if handle == "" then
return nil
else
@@ -451,14 +450,6 @@ function skynet.queryservice(global, ...)
end
end
local function group_command(cmd, handle, address)
if address then
return string.format("%s %d :%x",cmd, handle, address)
else
return string.format("%s %d",cmd,handle)
end
end
function skynet.address(addr)
if type(addr) == "number" then
return string.format(":%x",addr)
@@ -479,66 +470,10 @@ function skynet.error(...)
return c.error(table.concat(t, " "))
end
----- debug
local internal_info_func
function skynet.info_func(func)
internal_info_func = func
end
local dbgcmd = {}
function dbgcmd.MEM()
local kb, bytes = collectgarbage "count"
skynet.ret(skynet.pack(kb,bytes))
end
function dbgcmd.GC()
coroutine_pool = {}
collectgarbage "collect"
end
function dbgcmd.STAT()
local stat = {}
stat.mqlen = skynet.mqlen()
skynet.ret(skynet.pack(stat))
end
function dbgcmd.INFO()
if internal_info_func then
skynet.ret(skynet.pack(internal_info_func()))
else
skynet.ret(skynet.pack(nil))
end
end
local function _debug_dispatch(session, address, cmd, ...)
local f = dbgcmd[cmd]
assert(f, cmd)
f(...)
end
----- register protocol
do
local REG = skynet.register_protocol
REG {
name = "text",
id = skynet.PTYPE_TEXT,
pack = function (...)
local n = select ("#" , ...)
if n == 0 then
return ""
elseif n == 1 then
return tostring(...)
else
return table.concat({...}," ")
end
end,
unpack = c.tostring
}
REG {
name = "lua",
id = skynet.PTYPE_LUA,
@@ -551,14 +486,6 @@ do
id = skynet.PTYPE_RESPONSE,
}
REG {
name = "debug",
id = skynet.PTYPE_DEBUG,
pack = skynet.pack,
unpack = skynet.unpack,
dispatch = _debug_dispatch,
}
REG {
name = "error",
id = skynet.PTYPE_ERROR,
@@ -603,10 +530,10 @@ local function init_service(start)
local ok, err = xpcall(init_template, debug.traceback, start)
if not ok then
print("init service failed:", err)
skynet.send(".launcher","text", "ERROR")
skynet.send(".launcher","lua", "ERROR")
skynet.exit()
else
skynet.send(".launcher","text", "")
skynet.send(".launcher","lua", "LAUNCHOK")
end
end
@@ -649,4 +576,8 @@ function skynet.mqlen()
return tonumber(c.command "MQLEN")
end
-- Inject internal debug framework
local debug = require "skynet.debug"
debug(skynet)
return skynet

49
lualib/skynet/debug.lua Normal file
View File

@@ -0,0 +1,49 @@
return function (skynet)
local internal_info_func
function skynet.info_func(func)
internal_info_func = func
end
local dbgcmd = {}
function dbgcmd.MEM()
local kb, bytes = collectgarbage "count"
skynet.ret(skynet.pack(kb,bytes))
end
function dbgcmd.GC()
coroutine_pool = {}
collectgarbage "collect"
end
function dbgcmd.STAT()
local stat = {}
stat.mqlen = skynet.mqlen()
skynet.ret(skynet.pack(stat))
end
function dbgcmd.INFO()
if internal_info_func then
skynet.ret(skynet.pack(internal_info_func()))
else
skynet.ret(skynet.pack(nil))
end
end
local function _debug_dispatch(session, address, cmd, ...)
local f = dbgcmd[cmd]
assert(f, cmd)
f(...)
end
skynet.register_protocol {
name = "debug",
id = assert(skynet.PTYPE_DEBUG),
pack = assert(skynet.pack),
unpack = assert(skynet.unpack),
dispatch = _debug_dispatch,
}
end

View File

@@ -1,5 +1,5 @@
local skynet = require "skynet"
local snax_interface = require "snax_interface"
local snax_interface = require "snax.interface"
local snax = {}
local typeclass = {}

View File

@@ -1,4 +1,4 @@
local si = require "snax_interface"
local si = require "snax.interface"
local io = io
local hotfix = {}