Start with luadebug
This commit is contained in:
@ -9,7 +9,12 @@ config.plugins.jpdebug = {
|
|||||||
["test"] = {
|
["test"] = {
|
||||||
type = "shell",
|
type = "shell",
|
||||||
cmd = {"lua", "test.lua"}
|
cmd = {"lua", "test.lua"}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
default_target = "test"
|
["luadebug"] = {
|
||||||
|
type = "luadebug",
|
||||||
|
entry = "test.lua",
|
||||||
|
cwd = ".",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default_target = "luadebug"
|
||||||
}
|
}
|
||||||
|
|||||||
32
init.lua
32
init.lua
@ -13,7 +13,9 @@ core.jpdebug = core.jpdebug or {}
|
|||||||
-- Global list of all the runners
|
-- Global list of all the runners
|
||||||
core.jpdebug.runners = core.jpdebug.runners or {}
|
core.jpdebug.runners = core.jpdebug.runners or {}
|
||||||
local runner_shell = require("plugins.jpdebug.runners.shell")
|
local runner_shell = require("plugins.jpdebug.runners.shell")
|
||||||
|
local runner_luadebug = require("plugins.jpdebug.runners.luadebug")
|
||||||
core.jpdebug.runners[runner_shell.name] = runner_shell
|
core.jpdebug.runners[runner_shell.name] = runner_shell
|
||||||
|
core.jpdebug.runners[runner_luadebug.name] = runner_luadebug
|
||||||
|
|
||||||
-- Currently used view
|
-- Currently used view
|
||||||
local active_view = nil
|
local active_view = nil
|
||||||
@ -67,6 +69,18 @@ local function get_plugin_directory()
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Simple function splitting strings
|
||||||
|
local function stringsplit(inputstr, sep)
|
||||||
|
if sep == nil then
|
||||||
|
sep = "%s"
|
||||||
|
end
|
||||||
|
local t = {}
|
||||||
|
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
|
||||||
|
table.insert(t, str)
|
||||||
|
end
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
-- ---------- JPDebugView: a simple scrollable log view ----------
|
-- ---------- JPDebugView: a simple scrollable log view ----------
|
||||||
---@class JPDebugView : core.view
|
---@class JPDebugView : core.view
|
||||||
local JPDebugView = View:extend()
|
local JPDebugView = View:extend()
|
||||||
@ -92,11 +106,14 @@ end
|
|||||||
function JPDebugView:push(kind, s)
|
function JPDebugView:push(kind, s)
|
||||||
--TODO do some things with kind here
|
--TODO do some things with kind here
|
||||||
if not s or s == "" then return end
|
if not s or s == "" then return end
|
||||||
self.lines[#self.lines + 1] = s
|
local lines = stringsplit(s, "\n")
|
||||||
|
for _,l in pairs(lines) do
|
||||||
|
self.lines[#self.lines + 1] = l
|
||||||
if #self.lines > self.max_lines then
|
if #self.lines > self.max_lines then
|
||||||
local drop = #self.lines - self.max_lines
|
local drop = #self.lines - self.max_lines
|
||||||
for _ = 1, drop do table.remove(self.lines, 1) end
|
for _ = 1, drop do table.remove(self.lines, 1) end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
-- autoscroll to bottom
|
-- autoscroll to bottom
|
||||||
self.scroll.to.y = self:get_scrollable_size()
|
self.scroll.to.y = self:get_scrollable_size()
|
||||||
core.redraw = true
|
core.redraw = true
|
||||||
@ -160,16 +177,12 @@ local function run_target(target, name)
|
|||||||
for runner_name,runner in pairs(core.jpdebug.runners) do
|
for runner_name,runner in pairs(core.jpdebug.runners) do
|
||||||
if runner_name == target.type then
|
if runner_name == target.type then
|
||||||
-- Found a runner
|
-- Found a runner
|
||||||
running_proc = runner:run(target.cmd, {
|
running_proc = runner:run(target, name)
|
||||||
cwd = target.cwd or ".",
|
|
||||||
env = target.env or {},
|
|
||||||
stdout = process.REDIRECT_PIPE,
|
|
||||||
stderr = process.REDIRECT_PIPE
|
|
||||||
}, name)
|
|
||||||
running_runner = runner
|
running_runner = runner
|
||||||
|
|
||||||
if running_proc == nil then
|
if running_proc == nil then
|
||||||
core.error("[jpdebug] Could not run the target")
|
core.error("[jpdebug] Could not run the target")
|
||||||
|
view:push("stderr", "Could not run the target")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -192,8 +205,10 @@ local function run_target(target, name)
|
|||||||
local err = runner:read_stderr(running_proc)
|
local err = runner:read_stderr(running_proc)
|
||||||
if err ~= nil and err ~= "" then view:push("stderr", err) end
|
if err ~= nil and err ~= "" then view:push("stderr", err) end
|
||||||
end
|
end
|
||||||
local code = runner:wait(process.WAIT_INFINITE)
|
if running_proc then
|
||||||
|
local code = runner:wait(running_proc, process.WAIT_INFINITE)
|
||||||
view:push("stdout", ("\n[exit] code=%s\n"):format(tostring(code)))
|
view:push("stdout", ("\n[exit] code=%s\n"):format(tostring(code)))
|
||||||
|
end
|
||||||
running_proc = nil
|
running_proc = nil
|
||||||
running_runner = nil
|
running_runner = nil
|
||||||
end)
|
end)
|
||||||
@ -203,6 +218,7 @@ local function run_target(target, name)
|
|||||||
end
|
end
|
||||||
-- No suitable runners found
|
-- No suitable runners found
|
||||||
core.error("[jpdebug] No suitable runners found for target %s", name)
|
core.error("[jpdebug] No suitable runners found for target %s", name)
|
||||||
|
view:push("stderr", "No suitable runners found for target "..name)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ---------- Add toolbar to treeview if plugins are installed ------
|
-- ---------- Add toolbar to treeview if plugins are installed ------
|
||||||
|
|||||||
46
runners/luadebug.lua
Normal file
46
runners/luadebug.lua
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
local core = require "core"
|
||||||
|
local process = require "process"
|
||||||
|
|
||||||
|
---@class LDB
|
||||||
|
local LDB = {
|
||||||
|
name = "luadebug"
|
||||||
|
}
|
||||||
|
|
||||||
|
---@param target table Target table
|
||||||
|
---@param name string Name of the target to run
|
||||||
|
---@return process|nil
|
||||||
|
function LDB:run(target, name)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Wait untill it ends, possibly with timeout
|
||||||
|
---@param proc process Process object
|
||||||
|
---@param time any Time field, process.WAIT_INFINITE
|
||||||
|
function LDB:wait(proc, time)
|
||||||
|
return proc:wait(time)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Read the stdout, returns nil if process has stopped
|
||||||
|
---@param proc process Process object
|
||||||
|
function LDB:read_stdout(proc)
|
||||||
|
return proc:read_stdout()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Read the stderr
|
||||||
|
---@param proc process Process object
|
||||||
|
function LDB:read_stderr(proc)
|
||||||
|
return proc:read_stderr()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Kill the process
|
||||||
|
---@param proc process Process object
|
||||||
|
function LDB:kill(proc)
|
||||||
|
proc:kill()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Terminate the process
|
||||||
|
---@param proc process Process object
|
||||||
|
function LDB:terminate(proc)
|
||||||
|
proc:terminate()
|
||||||
|
end
|
||||||
|
|
||||||
|
return LDB
|
||||||
@ -7,14 +7,19 @@ local M = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
-- Run a shell command
|
-- Run a shell command
|
||||||
---@param cmd table|string List of command pieces or in full
|
---@param target table Target table
|
||||||
---@param opts table Options to run the command. Should contain env (table), cwd (string), stdout and stdin
|
|
||||||
---@param name string Name of the target to run
|
---@param name string Name of the target to run
|
||||||
---@return process|nil
|
---@return process|nil
|
||||||
function M:run(cmd, opts, name)
|
function M:run(target, name)
|
||||||
core.log("[jpdebug] Running shell command")
|
core.log("[jpdebug] Running shell command")
|
||||||
if cmd then
|
local opts = {
|
||||||
local proc = process.start(cmd, opts)
|
cwd = target.cwd or ".",
|
||||||
|
env = target.env or {},
|
||||||
|
stdout = process.REDIRECT_PIPE,
|
||||||
|
stderr = process.REDIRECT_PIPE
|
||||||
|
}
|
||||||
|
if target.cmd then
|
||||||
|
local proc = process.start(target.cmd, opts)
|
||||||
return proc
|
return proc
|
||||||
else
|
else
|
||||||
core.error("[jpdebug] command not specified for target %s", name)
|
core.error("[jpdebug] command not specified for target %s", name)
|
||||||
|
|||||||
8
test.lua
8
test.lua
@ -1,8 +1,6 @@
|
|||||||
local socket = require 'socket'
|
|
||||||
|
|
||||||
print("Starting loop: test 123")
|
print("Starting loop: test 123")
|
||||||
for i = 1,100 do
|
for i = 1,10 do
|
||||||
socket.sleep(0.5)
|
print("i = ", i) -- we'll stop here
|
||||||
print("i =", i) -- we'll stop here
|
require("socket").sleep(1)
|
||||||
end
|
end
|
||||||
print("Yaaayyyy it works perfectly fine :)")
|
print("Yaaayyyy it works perfectly fine :)")
|
||||||
|
|||||||
Reference in New Issue
Block a user