snax : a simple skynet auxliliary framework

This commit is contained in:
Cloud Wu
2014-04-16 20:12:17 +08:00
parent a420fe498f
commit df5c619a29
6 changed files with 235 additions and 22 deletions

33
service/snaxd.lua Normal file
View File

@@ -0,0 +1,33 @@
local skynet = require "skynet"
local snax_interface = require "snax_interface"
local func = snax_interface(tostring(...), _ENV)
skynet.start(function()
local init = false
skynet.dispatch("lua", function ( _, _, id, ...)
local method = func[id]
if method[2] == "system" then
if method[3] == "init" then
assert(not init, "Already init")
local initfunc = method[4] or function() end
skynet.ret(skynet.pack(initfunc(...)))
init = true
else
assert(init, "Never init")
local exitfunc = method[4] or function() end
skynet.ret(skynet.pack(exitfunc(...)))
init = false
skynet.exit()
end
else
assert(init, "Init first")
if method[2] == "subscribe" then
-- no return
method[4](...)
else
skynet.ret(skynet.pack(method[4](...)))
end
end
end)
end)