mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-16 01:26:09 +00:00
Scripts: File › Scripts runs the text its check read, with includes from the checked folder
The menu item checked a listed script and then ran script.run by its path,
which opened the file again; a link put in place of the file or a folder on
its path in between could make it run a file the check never saw, and the
include folder was looked up from the path again as well.
script.run takes installed: true. With a path it reads the file once through
script::folder::read, runs that text, and reads #include and $.evalFile in the
Scripts folder's real path followed by the names that read found. The menu
item runs script.run {path, installed: true}.
This commit is contained in:
@@ -295,12 +295,14 @@ fn display(path: &Path) -> Arc<str> {
|
||||
|
||||
impl Files {
|
||||
/// The files of a run of the script at `path` (`None` for a script given as text), with the
|
||||
/// `JSINCLUDE` folders `jsinclude`.
|
||||
pub(crate) fn new(path: Option<&str>, jsinclude: Vec<PathBuf>) -> Self {
|
||||
let real = path.and_then(|p| std::fs::canonicalize(p).ok());
|
||||
/// `JSINCLUDE` folders `jsinclude`. `checked` is the script's real path when the read of its text
|
||||
/// found it, which the run's folder then comes from; without it, `path` is looked up.
|
||||
pub(crate) fn new(path: Option<&str>, checked: Option<PathBuf>, jsinclude: Vec<PathBuf>) -> Self {
|
||||
let scope_of_checked = checked.as_deref().and_then(Path::parent).map(|d| ScriptScope::of_real_folder(d.to_path_buf()));
|
||||
let real = checked.or_else(|| path.and_then(|p| std::fs::canonicalize(p).ok()));
|
||||
let dir = real.as_deref().and_then(folder_of);
|
||||
Self {
|
||||
scope: dir.as_deref().map(ScriptScope::of_folder).unwrap_or_default(),
|
||||
scope: scope_of_checked.or_else(|| dir.as_deref().map(ScriptScope::of_folder)).unwrap_or_default(),
|
||||
jsinclude,
|
||||
include_path: Vec::new(),
|
||||
files: 0,
|
||||
|
||||
@@ -163,6 +163,9 @@ pub(crate) struct Request {
|
||||
pub name_given: bool,
|
||||
/// The file the script was read from, which its included files are read beside.
|
||||
pub file: Option<String>,
|
||||
/// The real path of `file` as the read of `source` found it, which the included files are then
|
||||
/// read beside instead of looking `file` up again.
|
||||
pub checked_real: Option<std::path::PathBuf>,
|
||||
pub source: String,
|
||||
pub args: Map<String, Value>,
|
||||
pub fuel: u64,
|
||||
@@ -1814,7 +1817,7 @@ impl Session {
|
||||
self.script_high_water.retain(|uid, _| open.contains(uid));
|
||||
self.script_stop.clear();
|
||||
self.script_report = None;
|
||||
let mut files = include::Files::new(request.file.as_deref(), include::Files::jsinclude_env());
|
||||
let mut files = include::Files::new(request.file.as_deref(), request.checked_real, include::Files::jsinclude_env());
|
||||
let expanded = files.expand_script(&request.source);
|
||||
let name = match &expanded {
|
||||
Ok(include::Expanded { name: Some(name), .. }) if !request.name_given => name.clone(),
|
||||
|
||||
Reference in New Issue
Block a user