diff options
| author | venomade <venomade@venomade.com> | 2026-05-21 20:34:45 +0100 |
|---|---|---|
| committer | venomade <venomade@venomade.com> | 2026-05-21 20:34:45 +0100 |
| commit | 637409d951e9dd1a2c29cd424bd41ff8c14b6d88 (patch) | |
| tree | 2d41be117f6a9f62562c7b54f06a1b1780c62a3b /lua_src/main.lua | |
Initial Commit main
Diffstat (limited to 'lua_src/main.lua')
| -rw-r--r-- | lua_src/main.lua | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/lua_src/main.lua b/lua_src/main.lua new file mode 100644 index 0000000..776f2a4 --- /dev/null +++ b/lua_src/main.lua @@ -0,0 +1,48 @@ +local config = require("sild.config") +local parse = require("sild.parse") +local session = require("sild.session") +local debugger = require("sild.debugger") +local commands = require("sild.commands") + +local cli = config.parse_cli(arg) + +if not cli.script_path then + config.print_help(SILD_VERSION); os.exit(1) +end + +local home = os.getenv("HOME") or os.getenv("USERPROFILE") or "" +local xdg_config_home = os.getenv("XDG_CONFIG_HOME") or (home .. "/.config") +config.parse_file(cli.config_file or (xdg_config_home .. "/sild/sild.cfg")) + +local chunk, load_err = loadfile(cli.script_path) +if not chunk then + local ansi = require("sild.ansi") + io.stderr:write(ansi.color_error( + "ERROR: cannot load '" .. cli.script_path .. "': " .. tostring(load_err) + ) .. "\n") + os.exit(1) +end + +local script_src_key = "@" .. cli.script_path +-- TODO: Look for annotations in require'd files +local breakpoints_list, actions_list = parse.annotations(cli.script_path) +session.breakpoints[script_src_key] = breakpoints_list +for _, ln in ipairs(cli.breaks) do + session.breakpoints[script_src_key][ln] = true +end +session.actions[script_src_key] = actions_list + +local real_arg = {} +for i, v in ipairs(cli.script_args) do real_arg[i] = v end +real_arg[0] = cli.script_path +arg = real_arg + +local ansi = require("sild.ansi") +print(ansi.color_prompt("sild " .. SILD_VERSION) .. " " .. ansi.color_bold(cli.script_path)) +print(ansi.color_dim("n=step c=continue ?=help q=quit") .. " " .. + -- TODO: use XDG_CONFIG_HOME here + ansi.color_dim("config: " .. (cli.config_file or (os.getenv("HOME") or "~") .. "/.config/sild/sild.cfg")) .. "\n") + +local has_immediate_bp = next(session.breakpoints[script_src_key]) ~= nil +debugger.install_hook(has_immediate_bp, commands.run) +chunk() |
