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()