diff options
Diffstat (limited to 'meta/3rd/skynet/library/skynet.lua')
-rw-r--r-- | meta/3rd/skynet/library/skynet.lua | 73 |
1 files changed, 39 insertions, 34 deletions
diff --git a/meta/3rd/skynet/library/skynet.lua b/meta/3rd/skynet/library/skynet.lua index 843722c4..f09d996c 100644 --- a/meta/3rd/skynet/library/skynet.lua +++ b/meta/3rd/skynet/library/skynet.lua @@ -13,34 +13,34 @@ ---|+'"trace"' ---@alias SERVICEADDR '".servicename"' | '":0000000C"' | integer ---@alias MESSAGEHANDLER fun(session:integer, source:integer, cmd:string, ...) -local skynet = { - -- read skynet.h - PTYPE_TEXT = 0, - PTYPE_RESPONSE = 1, - PTYPE_MULTICAST = 2, - PTYPE_CLIENT = 3, - PTYPE_SYSTEM = 4, - PTYPE_HARBOR = 5, - PTYPE_SOCKET = 6, - PTYPE_ERROR = 7, - PTYPE_QUEUE = 8, -- used in deprecated mqueue, use skynet.queue instead - PTYPE_DEBUG = 9, - PTYPE_LUA = 10, - PTYPE_SNAX = 11, - PTYPE_TRACE = 12, -- use for debug trace - PNAME_TEXT = "text", - PNAME_RESPONSE = "response", - PNAME_MULTICAST = "muliticast", - PNAME_CLIENT = "client", - PNAME_SYSTEM = "system", - PNAME_HARBOR = "harbor", - PNAME_SOCKET = "socket", - PNAME_ERROR = "error", - PNAME_QUEUE = "queue", - PNAME_DEBUG = "debug", - PNAME_LUA = "lua", - PNAME_SNAX = "snax", - PNAME_TRACE = "trace", +local skynet = { + -- read skynet.h + PTYPE_TEXT = 0, + PTYPE_RESPONSE = 1, + PTYPE_MULTICAST = 2, + PTYPE_CLIENT = 3, + PTYPE_SYSTEM = 4, + PTYPE_HARBOR = 5, + PTYPE_SOCKET = 6, + PTYPE_ERROR = 7, + PTYPE_QUEUE = 8, -- used in deprecated mqueue, use skynet.queue instead + PTYPE_DEBUG = 9, + PTYPE_LUA = 10, + PTYPE_SNAX = 11, + PTYPE_TRACE = 12, -- use for debug trace + PNAME_TEXT = "text", + PNAME_RESPONSE = "response", + PNAME_MULTICAST = "muliticast", + PNAME_CLIENT = "client", + PNAME_SYSTEM = "system", + PNAME_HARBOR = "harbor", + PNAME_SOCKET = "socket", + PNAME_ERROR = "error", + PNAME_QUEUE = "queue", + PNAME_DEBUG = "debug", + PNAME_LUA = "lua", + PNAME_SNAX = "snax", + PNAME_TRACE = "trace", } @@ -103,8 +103,8 @@ end ---* 你需要挂起一个请求,等将来时机满足,再回应它。而回应的时候已经在别的 coroutine 中了。 ---针对这种情况,你可以调用 skynet.response(skynet.pack) 获得一个闭包,以后调用这个闭包即可把回应消息发回。 ---这里的参数 skynet.pack 是可选的,你可以传入其它打包函数,默认即是 skynet.pack 。 ----@param msg lightuserdata ----@param sz integer +---@param msg lightuserdata|string +---@param sz? integer function skynet.ret(msg, sz) end @@ -205,7 +205,7 @@ end ---@param addr SERVICEADDR @目标服务地址 ---@param typename string @类型名 ---@param msg lightuserdata ----@param sz number +---@param sz? number function skynet.rawsend(addr, typename, msg, sz) end @@ -217,6 +217,7 @@ end ---@param addr SERVICEADDR @目标服务地址 ---@param typename string @类型名 ---@vararg any @传输的数据 +---@return ... function skynet.call(addr, typename, ...) end @@ -227,8 +228,8 @@ end ---* 挂起期间,状态可能会变更,造成重入 ---@param addr SERVICEADDR @目标服务地址 ---@param typename string @类型名 ----@param msg lightuserdata ----@param sz number +---@param msg lightuserdata|string +---@param sz? number function skynet.rawcall(addr, typename, msg, sz) end @@ -240,8 +241,10 @@ request.__call = request.add ---@param obj table # {addr, typename, ...} function request:add(obj) end + function request:close() end + function request:select(timeout) end @@ -249,6 +252,7 @@ end ---@return request function skynet.request(obj) end + ---* 返回一个唯一的会话ID ---@return number function skynet.genid() @@ -293,7 +297,7 @@ end --- 用于启动一个新的 Lua 服务。name 是脚本的名字(不用写 .lua 后缀)。只有被启动的脚本的 start 函数返回后,这个 API 才会返回启动的服务的地址,这是一个阻塞 API 。如果被启动的脚本在初始化环节抛出异常,或在初始化完成前就调用 skynet.exit 退出,skynet.newservice 都会抛出异常。如果被启动的脚本的 start 函数是一个永不结束的循环,那么 newservice 也会被永远阻塞住。 --- > 启动参数其实是以字符串拼接的方式传递过去的。所以不要在参数中传递复杂的 Lua 对象。接收到的参数都是字符串,且字符串中不可以有空格(否则会被分割成多个参数)。这种参数传递方式是历史遗留下来的,有很多潜在的问题。目前推荐的惯例是,让你的服务响应一个启动消息。在 newservice 之后,立刻调用 skynet.call 发送启动请求。 ---@param name string #脚本名字 ----@vararg string #可选参数 +---@vararg string|number #可选参数 function skynet.newservice(name, ...) end @@ -546,4 +550,5 @@ end function skynet.info_func(fun) end + return skynet |