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, ...)
end
function skynet.uniqueservice(global, ...)
if global == true then
function skynet.uniqueservice(name, ...)
if name == true then
return assert(skynet.call(".service", "lua", "GLAUNCH", ...))
else
return assert(skynet.call(".service", "lua", "LAUNCH", global, ...))
return assert(skynet.call(".service", "lua", "LAUNCH", name, ...))
end
end
function skynet.queryservice(global, ...)
if global == true then
function skynet.queryservice(name, ...)
if name == true then
return assert(skynet.call(".service", "lua", "GQUERY", ...))
else
return assert(skynet.call(".service", "lua", "QUERY", global, ...))
return assert(skynet.call(".service", "lua", "QUERY", name, ...))
end
end

View File

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

View File

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

View File

@@ -40,16 +40,16 @@ local function collect_uv(f , uv, env)
end
local function collect_all_uv(funcs)
local global = {}
local globals = {}
for _, v in pairs(funcs) do
if v[4] then
collect_uv(v[4], global, envid(v[4]))
collect_uv(v[4], globals, envid(v[4]))
end
end
if not global["_ENV"] then
global["_ENV"] = {func = collect_uv, index = 1}
if not globals["_ENV"] then
globals["_ENV"] = {func = collect_uv, index = 1}
end
return global
return globals
end
local function loader(source)
@@ -70,40 +70,40 @@ end
local dummy_env = {}
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
while true do
local name, value = debug.getupvalue(f, i)
if name == nil then
break
elseif value == nil or value == dummy_env then
local old_uv = global[name]
local old_uv = globals[name]
if old_uv then
debug.upvaluejoin(f, i, old_uv.func, old_uv.index)
end
else
if type(value) == "function" then
_patch(global, value)
_patch(globals, value)
end
end
i = i + 1
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))
_patch(global, f)
_patch(globals, f)
desc[4] = f
end
local function inject(funcs, 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
local _, group, name, f = table.unpack(v)
if f then
patch_func(funcs, global, group, name, f)
patch_func(funcs, globals, group, name, f)
end
end

View File

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

View File

@@ -96,10 +96,11 @@ function cmd.QUERY(service_name, subname)
end
local function list_service()
local val
local result = {}
for k,v in pairs(service) do
if type(v) == "string" then
v = "Error: " .. v
val = "Error: " .. v
elseif type(v) == "table" then
local querying = {}
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)))
end
end
v = table.concat(querying, "\n")
val = table.concat(querying, "\n")
else
v = skynet.address(v)
val = skynet.address(v)
end
result[k] = v
result[k] = val
end
return result