pkulchenko / ZeroBraneStudio

Lightweight Lua-based IDE for Lua with code completion, syntax highlighting, live coding, remote debugger, and code analyzer; supports Lua 5.1, 5.2, 5.3, 5.4, LuaJIT and other Lua interpreters on Windows, macOS, and Linux
http://studio.zerobrane.com/
Other
2.62k stars 519 forks source link

remote console multi variables access bug #1149

Closed robertlzj closed 2 years ago

robertlzj commented 2 years ago

In Local console

>a,b,c=1,2,3 --'>': input
>a,c=nil
>b
2 --after input get v
>a,b,c
nil 2

Everything is correct. But, in Remote console:

>a,b,c=1,2,3 --'>': input
>a,c=nil
>b
2 --after input get v
>a,b,c
nil --which should be 'nil, 2, nil' I think

Win10 x64, Lua 5.3 x32

pkulchenko commented 2 years ago

The issue appears to be in the debugger and because it's using a table to collect the values, the result is Lua version-dependent (it's 5.1 in the local console and 5.3 in the remote console).

Can you check the following patch, as it fixes the issue for me:

diff --git a/lualibs/mobdebug/mobdebug.lua b/lualibs/mobdebug/mobdebug.lua
index 6d83fa28..36fa14c3 100644
--- a/lualibs/mobdebug/mobdebug.lua
+++ b/lualibs/mobdebug/mobdebug.lua
@@ -19,7 +19,7 @@ end)("os")

 local mobdebug = {
   _NAME = "mobdebug",
-  _VERSION = "0.802",
+  _VERSION = "0.803",
   _COPYRIGHT = "Paul Kulchenko",
   _DESCRIPTION = "Mobile Remote Debugger for the Lua programming language",
   port = os and os.getenv and tonumber((os.getenv("MOBDEBUG_PORT"))) or 8172,
@@ -731,9 +731,9 @@ local function stringify_results(params, status, ...)
   if params.nocode == nil then params.nocode = true end
   if params.comment == nil then params.comment = 1 end

-  local t = {...}
-  for i,v in pairs(t) do -- stringify each of the returned values
-    local ok, res = pcall(mobdebug.line, v, params)
+  local t = {}
+  for i = 1, select('#', ...) do -- stringify each of the returned values
+    local ok, res = pcall(mobdebug.line, select(i, ...), params)
     t[i] = ok and res or ("%q"):format(res):gsub("\010","n"):gsub("\026","\\026")
   end
   -- stringify table with all returned values
robertlzj commented 2 years ago

Hi, it works as expected, thank you~