scm: support --eval
With the ~--eval~ option you can evaluate an expression in mu/scm environment. For example: $ mu scm --eval \ '(format #t "found ~d match(es)\n" (length (mfind "hello")))' found 7173 match(es) Add command-line parameter and implement.
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright (C) 2010-2025 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
** Copyright (C) 2010-2026 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the GNU General Public License as published by the
|
||||
@ -75,7 +75,9 @@ cmd_scm(const Store& store, const Options& opts)
|
||||
#else
|
||||
if (opts.scm.script_path)
|
||||
return Mu::Scm::run_script(store, opts, *opts.scm.script_path);
|
||||
else
|
||||
else if (opts.scm.eval)
|
||||
return Mu::Scm::run_eval(store, opts, *opts.scm.eval);
|
||||
else
|
||||
return Mu::Scm::run_repl(store, opts, opts.scm.socket_path.value_or(""));
|
||||
#endif /*BUILD_SCM*/
|
||||
}
|
||||
|
||||
@ -650,7 +650,9 @@ sub_scm(CLI::App& sub, Options& opts)
|
||||
->excludes("--listen");
|
||||
sub.add_option("script-args", opts.scm.params, "Parameters for script")
|
||||
->type_name("<parameters>");
|
||||
|
||||
sub.add_option("--eval", opts.scm.eval, "Expression to evaluate")
|
||||
->excludes("--listen")
|
||||
->excludes("script-path");
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright (C) 2022-2025 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
** Copyright (C) 2022-2026 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the GNU General Public License as published by the
|
||||
@ -261,6 +261,7 @@ struct Options {
|
||||
bool listen; /**< Whether to start listening on a socket */
|
||||
Option<std::string> socket_path; /**< path for the '--listen'
|
||||
* Unix domain socket */
|
||||
Option<std::string> eval; /**< expression to evaluate */
|
||||
} scm;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user