Single pump for both lua and mdb outputs
This commit is contained in:
@ -15,12 +15,29 @@ local function get_plugin_root()
|
||||
return dirname(here) -- …/jpdebug
|
||||
end
|
||||
|
||||
-- Check if string starts with a substring
|
||||
local function starts_with(str, word)
|
||||
return str:sub(1, #word) == word
|
||||
end
|
||||
|
||||
-- ------------------- Runner API --------------------------------
|
||||
|
||||
---@class luadebug: runner
|
||||
local luadebug = debugger.runner:new({
|
||||
name = "luadebug",
|
||||
proc = nil ---@type process|nil
|
||||
proc = nil, ---@type process|nil
|
||||
|
||||
caps = {
|
||||
can_pause = false,
|
||||
can_continue = true,
|
||||
can_step_in = true,
|
||||
can_step_over = true,
|
||||
can_step_out = true,
|
||||
can_breakpoints = true,
|
||||
has_stack = true,
|
||||
has_locals = true,
|
||||
can_eval = false,
|
||||
},
|
||||
})
|
||||
|
||||
function luadebug:run(target, name)
|
||||
@ -48,24 +65,13 @@ function luadebug:run(target, name)
|
||||
|
||||
self.on_state('connecting')
|
||||
|
||||
-- output pump
|
||||
core.add_thread(function()
|
||||
while true do
|
||||
core.redraw = true
|
||||
coroutine.yield(0.016) -- 60FPS
|
||||
local sout = self.proc:read_stdout()
|
||||
local serr = self.proc:read_stderr()
|
||||
if sout == nil or serr == nil then
|
||||
-- Make sure to read stderr for the last time
|
||||
if serr and serr~="" then self.on_stderr(serr) end
|
||||
local exitcode = self.proc:wait(process.WAIT_INFINITE)
|
||||
self.on_exit(exitcode)
|
||||
break
|
||||
end
|
||||
if sout and sout~="" then self.on_stdout(sout) end
|
||||
if serr and serr~="" then self.on_stderr(serr) end
|
||||
end
|
||||
end)
|
||||
-- Start output pump
|
||||
self:pumps()
|
||||
end
|
||||
|
||||
function luadebug:continue()
|
||||
self.mdb:write('run\n')
|
||||
self.on_state('running')
|
||||
end
|
||||
|
||||
function luadebug:wait(time)
|
||||
@ -171,28 +177,57 @@ function luadebug:spawn_mdb(lua)
|
||||
end
|
||||
|
||||
self.mdb = proc
|
||||
end
|
||||
|
||||
self.mdb:write('run\n')
|
||||
|
||||
-- output pump
|
||||
-- ---------------- Pumps ---------------------------------------
|
||||
function luadebug:pumps()
|
||||
core.add_thread(function()
|
||||
while true do
|
||||
core.redraw = true
|
||||
coroutine.yield(0.016) -- 60FPS
|
||||
local sout = self.mdb:read_stdout()
|
||||
local serr = self.mdb:read_stderr()
|
||||
if sout == nil or serr == nil then
|
||||
-- Make sure to read stderr for the last time
|
||||
|
||||
-- LUA PROGRAM OUTPUT
|
||||
if true then
|
||||
local sout = self.proc:read_stdout()
|
||||
local serr = self.proc:read_stderr()
|
||||
|
||||
if sout == nil or serr == nil then
|
||||
-- Make sure to read stderr for the last time
|
||||
if serr and serr~="" then self.on_stderr(serr) end
|
||||
local exitcode = self.proc:wait(process.WAIT_INFINITE)
|
||||
self.on_exit(exitcode)
|
||||
break
|
||||
end
|
||||
if sout and sout~="" then self.on_stdout(sout) end
|
||||
if serr and serr~="" then self.on_stderr(serr) end
|
||||
local exitcode = self.mdb:wait(process.WAIT_INFINITE)
|
||||
self.on_exit(exitcode)
|
||||
break
|
||||
end
|
||||
if sout and sout~="" then self.on_stdout('mdb> '..sout) end
|
||||
if serr and serr~="" then self.on_stderr('mdb> '..serr) end
|
||||
|
||||
-- MDB OUTPUT
|
||||
if true then
|
||||
local sout = self.mdb:read_stdout()
|
||||
local serr = self.mdb:read_stderr()
|
||||
|
||||
if sout == nil or serr == nil then
|
||||
-- Make sure to read stderr for the last time
|
||||
if serr and serr~="" then self.on_stderr(serr) end
|
||||
local exitcode = self.proc:wait(process.WAIT_INFINITE)
|
||||
self.on_exit(exitcode)
|
||||
break
|
||||
end
|
||||
if sout and sout~="" then self.on_stdout("mdb> "..sout) end
|
||||
if serr and serr~="" then self.on_stderr("mdb> "..serr) end
|
||||
|
||||
if sout and sout~="" then
|
||||
-- Check output
|
||||
if starts_with(sout, "Paused") then
|
||||
self.on_state('paused')
|
||||
self.on_break('?', -1, 'paused')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
return luadebug
|
||||
|
||||
return luadebug
|
||||
|
||||
Reference in New Issue
Block a user