args passed to debugger

This commit is contained in:
Christoph J. Scherr 2024-02-15 14:51:45 +01:00
parent c303f4a474
commit b3600561aa
Signed by: cscherrNT
GPG Key ID: 8E2B45BC51A27EA7
2 changed files with 814 additions and 743 deletions

File diff suppressed because it is too large Load Diff

67
lua/custom/utils.lua Normal file
View File

@ -0,0 +1,67 @@
local M = {}
-- this function will split a string into a table of tokens, like it would
-- be passed into the `argv` of a program that was executed from the commandline
--
-- @param string raw string of cli args that should be split
-- @return table tokens args as a table
M.tokenize_args = function(raw)
-- NOTE: string.gmatch is does not use regex, but a smaller pattern matcher!
-- A complete regex parser would be larger than lua itself. See
-- [Programming in Lua 20.2](https://www.lua.org/pil/20.2.html).
--
-- Notable differences:
-- '-' is ungreedy wildcard
-- '*?' does not work
-- '|' is not or
--
-- This means we're better of implementing the lexer with an algorithm.
local t = {}
local current = ""
local in_str = false
local str_seek
for c in string.gmatch(raw, ".") do -- iterate through all chars
if c == ' ' and not in_str then
if string.len(current) > 0 then
table.insert(t, current)
current = ""
end
elseif c == '"' and not in_str then
in_str = true
str_seek = '"'
elseif c == "'" and not in_str then
in_str = true
str_seek = "'"
elseif c == str_seek and in_str then
in_str = false
table.insert(t, current)
current = ""
else
current = current .. c
end
end
if string.len(current) > 0 then
table.insert(t, current)
end
return t
end
--- dumps a variable into a string, so it can be printed. This is meant for
--- debug prints
--- @param any t any variable
--- @return string t_dumped t dumped to string
M.dump = function(t)
if type(t) == 'table' then
local s = '{ '
for k, v in pairs(t) do
if type(k) ~= 'number' then k = '"' .. k .. '"' end
if k ~= 1 then
s = s .. ', '
end
s = s .. '[' .. k .. '] = \'' .. M.dump(v) .. '\''
end
return s .. ' }'
else
return tostring(t)
end
end
return M