Added separate debugger file and fixed shell to new form
This commit is contained in:
@ -18,7 +18,6 @@ end
|
||||
local function spawn_lua_process(entry, lua, cwd, env)
|
||||
local host = "localhost"
|
||||
local port = 8172
|
||||
local nowait = false
|
||||
|
||||
-- Resolve vendor/?.lua so "require('mobdebug')" finds the bundled file
|
||||
local vendor_glob = join(get_plugin_root(), "vendor/?.lua")
|
||||
@ -28,9 +27,8 @@ local function spawn_lua_process(entry, lua, cwd, env)
|
||||
local ok, m = pcall(require, "mobdebug"); if ok then
|
||||
print("Connecting to "..%q..":"..tostring(%d))
|
||||
local connected = m.start(%q, %d)
|
||||
if not connected and %s then m.off() end
|
||||
end
|
||||
]], host, port, host, port, nowait and "true" or "false")
|
||||
]], host, port, host, port)
|
||||
local launcher = string.format([[
|
||||
package.path = %q .. ";" .. package.path
|
||||
%s
|
||||
@ -74,8 +72,6 @@ function LDB:run(target, name, debuginfo)
|
||||
local cwd = target.cwd or "."
|
||||
local env = target.env or {}
|
||||
|
||||
-- TODO spawn the mobdebugger
|
||||
|
||||
-- spawn the main lua process
|
||||
local proc = spawn_lua_process(entry, lua, cwd, env)
|
||||
|
||||
@ -85,7 +81,7 @@ function LDB:run(target, name, debuginfo)
|
||||
end
|
||||
|
||||
return {
|
||||
luaproc=proc,
|
||||
luaproc=proc
|
||||
}
|
||||
end
|
||||
|
||||
@ -96,12 +92,14 @@ end
|
||||
|
||||
-- Read the stdout, returns nil if process has stopped
|
||||
function LDB:read_stdout(proc)
|
||||
return proc.luaproc:read_stdout()
|
||||
local sl = proc.luaproc:read_stdout()
|
||||
return sl
|
||||
end
|
||||
|
||||
-- Read the stderr
|
||||
function LDB:read_stderr(proc)
|
||||
return proc.luaproc:read_stderr()
|
||||
local sl = proc.luaproc:read_stderr()
|
||||
return sl
|
||||
end
|
||||
|
||||
-- Kill the process
|
||||
|
||||
@ -1,19 +1,32 @@
|
||||
local core = require "core"
|
||||
local process = require "process"
|
||||
|
||||
---@class M
|
||||
local M = {
|
||||
name = "shell"
|
||||
---@class shell: runner
|
||||
local shell = {
|
||||
name = "shell",
|
||||
proc = nil ---@type process|nil
|
||||
}
|
||||
|
||||
-- Run a shell command
|
||||
---@param target table Target table
|
||||
---@param name string Name of the target to run
|
||||
---@praam debuginfo table Debugging information
|
||||
---@return process|nil
|
||||
---@diagnostic disable-next-line: unused-local
|
||||
function M:run(target, name, debuginfo)
|
||||
core.log("[jpdebug] Running shell command")
|
||||
function shell:new(o)
|
||||
o = o or {}
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
end
|
||||
|
||||
---@meta
|
||||
function shell.log(msg) end
|
||||
---@meta
|
||||
function shell.error(msg) end
|
||||
---@meta
|
||||
function shell.stdout(msg) end
|
||||
---@meta
|
||||
function shell.stderr(msg) end
|
||||
---@meta
|
||||
function shell.exited() end
|
||||
|
||||
|
||||
function shell:run(target, name)
|
||||
local opts = {
|
||||
cwd = target.cwd or ".",
|
||||
env = target.env or {},
|
||||
@ -21,43 +34,46 @@ function M:run(target, name, debuginfo)
|
||||
stderr = process.REDIRECT_PIPE
|
||||
}
|
||||
if target.cmd then
|
||||
local proc = process.start(target.cmd, opts)
|
||||
return proc
|
||||
self.proc = process.start(target.cmd, opts)
|
||||
if not self.proc then
|
||||
self.error("Could not start process...")
|
||||
return
|
||||
end
|
||||
else
|
||||
core.error("[jpdebug] command not specified for target %s", name)
|
||||
self.error(string.format("command not specified for target %s", name))
|
||||
end
|
||||
|
||||
-- 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 and serr == nil then
|
||||
self.exited()
|
||||
break
|
||||
end
|
||||
if sout and sout~="" then self.stdout(sout) end
|
||||
if serr and serr~="" then self.stderr(serr) end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- Wait untill it ends, possibly with timeout
|
||||
---@param proc process Process object
|
||||
---@param time any Time field, process.WAIT_INFINITE
|
||||
function M:wait(proc, time)
|
||||
return proc:wait(time)
|
||||
function shell:wait(time)
|
||||
if not self.proc then return end
|
||||
return self.proc:wait(time)
|
||||
end
|
||||
|
||||
-- Read the stdout, returns nil if process has stopped
|
||||
---@param proc process Process object
|
||||
function M:read_stdout(proc)
|
||||
return proc:read_stdout()
|
||||
function shell:kill()
|
||||
if not self.proc then return end
|
||||
self.proc:kill()
|
||||
end
|
||||
|
||||
-- Read the stderr
|
||||
---@param proc process Process object
|
||||
function M:read_stderr(proc)
|
||||
return proc:read_stderr()
|
||||
function shell:terminate()
|
||||
if not self.proc then return end
|
||||
self.proc:terminate()
|
||||
end
|
||||
|
||||
-- Kill the process
|
||||
---@param proc process Process object
|
||||
function M:kill(proc)
|
||||
proc:kill()
|
||||
end
|
||||
|
||||
-- Terminate the process
|
||||
---@param proc process Process object
|
||||
function M:terminate(proc)
|
||||
proc:terminate()
|
||||
end
|
||||
|
||||
return M
|
||||
return shell
|
||||
|
||||
|
||||
Reference in New Issue
Block a user