From 81ec4505802555fd4596cccb7666fe7d4cc058d9 Mon Sep 17 00:00:00 2001 From: notify Date: Thu, 15 Jan 2026 11:12:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BB=8E=E5=85=83=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E8=8E=B7=E5=8F=96=E5=AD=97=E7=AC=A6=E4=B8=B2=E7=9A=84?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=B9=B6=E5=BA=94=E7=94=A8=E7=BB=99table?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extension/script/backend/worker/variables.lua | 73 ++++++++++++------- 1 file changed, 45 insertions(+), 28 deletions(-) diff --git a/extension/script/backend/worker/variables.lua b/extension/script/backend/worker/variables.lua index a42a4874..6e2495bc 100644 --- a/extension/script/backend/worker/variables.lua +++ b/extension/script/backend/worker/variables.lua @@ -339,6 +339,40 @@ local function varGetName(v) return ("%s: %s"):format(type, value) end +local function varGetStringValueFromMetaMethod(value, tp, allow_lazy) + local meta = rdebug.getmetatablev(value) + if meta == nil then return nil end + + local fn = rdebug.fieldv(meta, '__debugger_tostring') + if fn ~= nil then + local ok, res = rdebug.eval(fn, value) + if ok then + return res, tp + else + return "__debugger_tostring error: "..res, tp + end + end + + fn = rdebug.fieldv(meta, '__tostring') + if fn ~= nil then + if allow_lazy then + return tp, tp, true + else + local ok, res = rdebug.eval(fn, value) + if ok then + return res, tp + else + return "__tostring error: "..res, tp + end + end + end + + local name = rdebug.fieldv(meta, '__name') + if name ~= nil then + return rdebug.tostring(name), tp + end +end + local function varGetShortUserdata(value) local meta = rdebug.getmetatablev(value) if meta ~= nil then @@ -388,6 +422,13 @@ local function varGetShortValue(v) end local function varGetTableValue(t) + do + local ret1, ret2 = varGetStringValueFromMetaMethod(t, "table") + if ret1 then + return ret1, ret2 + end + end + local str = '' do local loct = rdebug.tablearrayv(t, 1 - arrayBase, SHORT_TABLE_ARRAY) @@ -482,35 +523,11 @@ local function varGetFunctionCode(v, value) end local function varGetUserdata(value, allow_lazy) - local meta = rdebug.getmetatablev(value) - if meta ~= nil then - local fn = rdebug.fieldv(meta, '__debugger_tostring') - if fn ~= nil then - local ok, res = rdebug.eval(fn, value) - if ok then - return res, "userdata" - else - return "__debugger_tostring error: "..res, "userdata" - end - end - local fn = rdebug.fieldv(meta, '__tostring') - if fn ~= nil then - if allow_lazy then - return 'userdata', "userdata", true - else - local ok, res = rdebug.eval(fn, value) - if ok then - return res, "userdata" - else - return "__tostring error: "..res, "userdata" - end - end - end - local name = rdebug.fieldv(meta, '__name') - if name ~= nil then - return rdebug.tostring(name), "userdata" - end + local ret1, ret2 = varGetStringValueFromMetaMethod(value, "userdata", allow_lazy) + if ret1 then + return ret1, ret2 end + return 'userdata', "userdata" end