From cc2ec8f292547a03ec458c100cf3e4cab9decee3 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 11 Nov 2026 00:00:48 -0800 Subject: [PATCH] =?UTF-8?q?Scripts:=20a=20script=20chosen=20from=20File=20?= =?UTF-8?q?=E2=80=BA=20Scripts=20reads=20its=20#include=20files=20and=20ru?= =?UTF-8?q?ns=20$.evalFile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit File › Scripts ran an installed script as source text, so the run had no file: an #include line ended it with "script file read refused", and $.evalFile was refused too. The menu now checks the script as before and runs it with script.run {path}, as docs/mcp.md describes, so its included files and the files $.evalFile runs are read beside it. --- crates/ui-egui/src/scripts_menu.rs | 7 ++++--- crates/ui-egui/src/tests/scripts_menu.rs | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/scripts_menu.rs b/crates/ui-egui/src/scripts_menu.rs index e62a5d887..9c890d5c3 100644 --- a/crates/ui-egui/src/scripts_menu.rs +++ b/crates/ui-egui/src/scripts_menu.rs @@ -242,13 +242,14 @@ pub fn readable(p: &Value) -> bool { } /// `ui.runInstalledScript {path}`: run the listed script at `path`. A script that is no longer in -/// the folder is not run, and the folder is read again. +/// the folder is not run, and the folder is read again. The script runs from its file, so its +/// `#include` lines and `$.evalFile` read beside it. pub fn run(app: &mut VectorcraftApp, p: &Value) -> Result { let path = p.get("path").and_then(Value::as_str).ok_or("missing `path`")?; - let source = app.session.installed_script(path).map_err(|e| { + app.session.installed_script(path).map_err(|e| { let ctx = app.ui_ctx.clone(); refresh(app, ctx.as_ref()); e.to_string() })?; - app.run("script.run", json!({"source": source, "name": vectorcraft_engine::cmd::fileio::file_name(path)})) + app.run("script.run", json!({ "path": path })) } diff --git a/crates/ui-egui/src/tests/scripts_menu.rs b/crates/ui-egui/src/tests/scripts_menu.rs index 3dc66acca..751bd528a 100644 --- a/crates/ui-egui/src/tests/scripts_menu.rs +++ b/crates/ui-egui/src/tests/scripts_menu.rs @@ -142,6 +142,20 @@ fn a_script_runs_its_own_file_whatever_its_name_ends_with() { let _ = std::fs::remove_dir_all(dir); } +#[test] +fn a_listed_script_reads_its_included_files_and_runs_files_beside_it() { + let dir = folder("include"); + let mut app = app(&dir); + write(&dir, "lib/two.jsxinc", DRAW); + write(&dir, "lib/one.js", "vc.run('shape.rectangle', {x:40,y:0,width:10,height:10});"); + let main = write(&dir, "Main.jsx", "#include \"lib/two.jsxinc\"\n$.evalFile('lib/one.js');\n"); + read(&app); + menus::run_ui_command(&mut app, scripts_menu::COMMAND, &json!({ "path": main })).unwrap().unwrap(); + finish(&mut app); + assert_eq!(objects(&app), 3, "{}", app.ui.status); + let _ = std::fs::remove_dir_all(dir); +} + #[test] fn script_and_folder_names_are_shown_as_they_are_in_every_language() { let dir = folder("language");