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.6k stars 519 forks source link

remote debugging debugger.redirect = "c" does only capture print, but not io.write or io.stdout:write #1109

Closed jjvbsag closed 3 years ago

jjvbsag commented 3 years ago

I'm struggling with capturing output. Running ZBS on a linux or Windows host (should not matter) There I have debugger.redirect = "c" in .zbstudio/user.lua set.

Doing Remote debug on an arm device basically using code sililar to this

    local script={}
    push(script,sprintf("arg={[0]=%q}",filename))
    push(script,sprintf('require("mobdebug").loop("%s")',ZBSHOSTNAME))
    local cmd=sprintf("/usr/bin/luajit -e'%s'&",join(script,';'))
    remote_execute(cmd)

(where push=table.insert, join=table.concat and sprintf=string.format)

Now, when debugging remote, I can see output of print("using print") in ZBS Output window, but I cannot see io.write('using io.write()\n') or io.stdout:write('using io.stdout:write()\n')

Is this an incompleteness in mobdebug? Any chance for a quick fix or workaround?

pkulchenko commented 3 years ago

It's mostly by design, as io.write and io.stdout:write are used less frequently and I wanted to have an alternative for some output to not be redirected. In terms of the workaround, you can probably apply the same logic to io.write as is applied to print (it's in mobdebug.lua on lines 1006-1020). This code intercepts the print call and sends its content back to the IDE. Another option is to assign io.write based on print in your code after require "mobdebug".start() is executed.

jjvbsag commented 3 years ago

Thank you for you response. I will try and come back to you.