diff --git a/lualib/skynet.lua b/lualib/skynet.lua index 3d3135db..36bb4d6d 100644 --- a/lualib/skynet.lua +++ b/lualib/skynet.lua @@ -24,7 +24,8 @@ local skynet = { PTYPE_ERROR = 7, PTYPE_QUEUE = 8, PTYPE_DEBUG = 9, - PTYPE_LUA = 10 + PTYPE_LUA = 10, + PTYPE_SNAX = 11, } -- code cache diff --git a/lualib/snax.lua b/lualib/snax.lua index 67dafc7e..cec97570 100644 --- a/lualib/snax.lua +++ b/lualib/snax.lua @@ -6,6 +6,14 @@ local typeclass = {} local G = { require = function() end } +skynet.register_protocol { + name = "snax", + id = skynet.PTYPE_SNAX, + pack = skynet.pack, + unpack = skynet.unpack, +} + + function snax.interface(name) if typeclass[name] then return typeclass[name] @@ -38,7 +46,7 @@ local function gen_post(type, handle) __index = function( t, k ) local id = assert(type.accept[k] , string.format("post %s no exist", k)) return function(...) - skynet_send(handle, "lua", id, ...) + skynet_send(handle, "snax", id, ...) end end }) end @@ -48,7 +56,7 @@ local function gen_req(type, handle) __index = function( t, k ) local id = assert(type.response[k] , string.format("request %s no exist", k)) return function(...) - return skynet_call(handle, "lua", id, ...) + return skynet_call(handle, "snax", id, ...) end end }) end @@ -69,7 +77,7 @@ function snax.newservice(name, ...) local handle = skynet.newservice("snaxd", name) assert(handle_cache[handle] == nil) if t.system.init then - skynet.call(handle, "lua", t.system.init, ...) + skynet.call(handle, "snax", t.system.init, ...) end local ret = wrapper(handle, name, t) handle_cache[handle] = ret @@ -90,7 +98,7 @@ end function snax.kill(obj, ...) local t = snax.interface(obj.type) - skynet_call(obj.handle, "lua", t.system.exit, ...) + skynet_call(obj.handle, "snax", t.system.exit, ...) end local function test_result(ok, ...) @@ -103,7 +111,7 @@ end function snax.hotfix(obj, source, ...) local t = snax.interface(obj.type) - return test_result(skynet_call(obj.handle, "lua", t.system.hotfix, source, ...)) + return test_result(skynet_call(obj.handle, "snax", t.system.hotfix, source, ...)) end return snax diff --git a/service/snaxd.lua b/service/snaxd.lua index 7783a7af..b7e1a359 100644 --- a/service/snaxd.lua +++ b/service/snaxd.lua @@ -2,6 +2,7 @@ local skynet = require "skynet" local c = require "skynet.c" local snax_interface = require "snax_interface" local profile = require "profile" +local snax = require "snax" local func = snax_interface(tostring(...), _ENV) local mode @@ -98,7 +99,7 @@ local function timing( method, ... ) end skynet.start(function() - skynet.dispatch("lua", function ( session , source , id, ...) + skynet.dispatch("snax", function ( session , source , id, ...) local method = func[id] if method[2] == "system" then