Support string address, see #1490 (#1491)

This commit is contained in:
云风
2021-10-22 17:43:07 +08:00
committed by GitHub
parent 599181ceaf
commit c008476417

View File

@@ -1,17 +1,30 @@
local skynet = require "skynet"
local c = require "skynet.core"
local function number_address(name)
local t = type(name)
if t == "number" then
return name
elseif t == "string" then
local hex = name:match "^:(%x+)"
if hex then
return tonumber(hex, 16)
end
end
end
function skynet.launch(...)
local addr = c.command("LAUNCH", table.concat({...}," "))
if addr then
return tonumber("0x" .. string.sub(addr , 2))
return tonumber(string.sub(addr , 2), 16)
end
end
function skynet.kill(name)
if type(name) == "number" then
skynet.send(".launcher","lua","REMOVE",name, true)
name = skynet.address(name)
local addr = number_address(name)
if addr then
skynet.send(".launcher","lua","REMOVE", addr, true)
name = skynet.address(addr)
end
c.command("KILL",name)
end