fix: 修复升级lua5.5后的兼容性错误 (#2123)

This commit is contained in:
bitcat🐱
2025-12-24 19:50:38 +08:00
committed by GitHub
parent 9f7634d477
commit a4c6e04ab0
6 changed files with 33 additions and 31 deletions

View File

@@ -992,19 +992,19 @@ function skynet.newservice(name, ...)
return skynet.call(".launcher", "lua" , "LAUNCH", "snlua", name, ...) return skynet.call(".launcher", "lua" , "LAUNCH", "snlua", name, ...)
end end
function skynet.uniqueservice(global, ...) function skynet.uniqueservice(name, ...)
if global == true then if name == true then
return assert(skynet.call(".service", "lua", "GLAUNCH", ...)) return assert(skynet.call(".service", "lua", "GLAUNCH", ...))
else else
return assert(skynet.call(".service", "lua", "LAUNCH", global, ...)) return assert(skynet.call(".service", "lua", "LAUNCH", name, ...))
end end
end end
function skynet.queryservice(global, ...) function skynet.queryservice(name, ...)
if global == true then if name == true then
return assert(skynet.call(".service", "lua", "GQUERY", ...)) return assert(skynet.call(".service", "lua", "GQUERY", ...))
else else
return assert(skynet.call(".service", "lua", "QUERY", global, ...)) return assert(skynet.call(".service", "lua", "QUERY", name, ...))
end end
end end

View File

@@ -213,10 +213,11 @@ end
local function compose_table(lines, msg) local function compose_table(lines, msg)
local tinsert = table.insert local tinsert = table.insert
tinsert(lines, count_cache[#msg]) tinsert(lines, count_cache[#msg])
local val
for _,v in ipairs(msg) do for _,v in ipairs(msg) do
v = tostring(v) val = tostring(v)
tinsert(lines,header_cache[#v]) tinsert(lines,header_cache[#val])
tinsert(lines,v) tinsert(lines,val)
end end
tinsert(lines, "\r\n") tinsert(lines, "\r\n")
return lines return lines

View File

@@ -130,11 +130,11 @@ local function parse_hosts()
end end
for host in hosts:gmatch("%S+") do for host in hosts:gmatch("%S+") do
host = host:lower() local h = host:lower()
local rt = rts[host] local rt = rts[h]
if not rt then if not rt then
rt = {} rt = {}
rts[host] = rt rts[h] = rt
end end
if not rt[family] then if not rt[family] then

View File

@@ -40,16 +40,16 @@ local function collect_uv(f , uv, env)
end end
local function collect_all_uv(funcs) local function collect_all_uv(funcs)
local global = {} local globals = {}
for _, v in pairs(funcs) do for _, v in pairs(funcs) do
if v[4] then if v[4] then
collect_uv(v[4], global, envid(v[4])) collect_uv(v[4], globals, envid(v[4]))
end end
end end
if not global["_ENV"] then if not globals["_ENV"] then
global["_ENV"] = {func = collect_uv, index = 1} globals["_ENV"] = {func = collect_uv, index = 1}
end end
return global return globals
end end
local function loader(source) local function loader(source)
@@ -70,40 +70,40 @@ end
local dummy_env = {} local dummy_env = {}
for k,v in pairs(_ENV) do dummy_env[k] = v end for k,v in pairs(_ENV) do dummy_env[k] = v end
local function _patch(global, f) local function _patch(globals, f)
local i = 1 local i = 1
while true do while true do
local name, value = debug.getupvalue(f, i) local name, value = debug.getupvalue(f, i)
if name == nil then if name == nil then
break break
elseif value == nil or value == dummy_env then elseif value == nil or value == dummy_env then
local old_uv = global[name] local old_uv = globals[name]
if old_uv then if old_uv then
debug.upvaluejoin(f, i, old_uv.func, old_uv.index) debug.upvaluejoin(f, i, old_uv.func, old_uv.index)
end end
else else
if type(value) == "function" then if type(value) == "function" then
_patch(global, value) _patch(globals, value)
end end
end end
i = i + 1 i = i + 1
end end
end end
local function patch_func(funcs, global, group, name, f) local function patch_func(funcs, globals, group, name, f)
local desc = assert(find_func(funcs, group, name) , string.format("Patch mismatch %s.%s", group, name)) local desc = assert(find_func(funcs, group, name) , string.format("Patch mismatch %s.%s", group, name))
_patch(global, f) _patch(globals, f)
desc[4] = f desc[4] = f
end end
local function inject(funcs, source, ...) local function inject(funcs, source, ...)
local patch = si("patch", dummy_env, loader(source)) local patch = si("patch", dummy_env, loader(source))
local global = collect_all_uv(funcs) local globals = collect_all_uv(funcs)
for _, v in pairs(patch) do for _, v in pairs(patch) do
local _, group, name, f = table.unpack(v) local _, group, name, f = table.unpack(v)
if f then if f then
patch_func(funcs, global, group, name, f) patch_func(funcs, globals, group, name, f)
end end
end end

View File

@@ -102,9 +102,9 @@ local function loadconfig(tmp)
local reload = {} local reload = {}
for name,address in pairs(tmp) do for name,address in pairs(tmp) do
if name:sub(1,2) == "__" then if name:sub(1,2) == "__" then
name = name:sub(3) local opt = name:sub(3)
config[name] = address config[opt] = address
skynet.error(string.format("Config %s = %s", name, address)) skynet.error(string.format("Config %s = %s", opt, address))
else else
assert(address == false or type(address) == "string") assert(address == false or type(address) == "string")
if node_address[name] ~= address then if node_address[name] ~= address then

View File

@@ -96,10 +96,11 @@ function cmd.QUERY(service_name, subname)
end end
local function list_service() local function list_service()
local val
local result = {} local result = {}
for k,v in pairs(service) do for k,v in pairs(service) do
if type(v) == "string" then if type(v) == "string" then
v = "Error: " .. v val = "Error: " .. v
elseif type(v) == "table" then elseif type(v) == "table" then
local querying = {} local querying = {}
if v.launch then if v.launch then
@@ -118,12 +119,12 @@ local function list_service()
table.insert(querying, skynet.address(detail.source) .. " " .. tostring(skynet.call(detail.source, "debug", "TASK", detail.session))) table.insert(querying, skynet.address(detail.source) .. " " .. tostring(skynet.call(detail.source, "debug", "TASK", detail.session)))
end end
end end
v = table.concat(querying, "\n") val = table.concat(querying, "\n")
else else
v = skynet.address(v) val = skynet.address(v)
end end
result[k] = v result[k] = val
end end
return result return result