From cc2ec8f292547a03ec458c100cf3e4cab9decee3 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 11 Nov 2026 00:00:48 -0800 Subject: [PATCH 1/2] =?UTF-8?q?Scripts:=20a=20script=20chosen=20from=20Fil?= =?UTF-8?q?e=20=E2=80=BA=20Scripts=20reads=20its=20#include=20files=20and?= =?UTF-8?q?=20runs=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"); From bc63dc7285971b2ee7bcae55bd73d0f473131910 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 11 Nov 2026 00:36:08 -0800 Subject: [PATCH 2/2] =?UTF-8?q?Scripts:=20the=20File=20=E2=80=BA=20Scripts?= =?UTF-8?q?=20command=20help=20says=20it=20runs=20the=20script=20by=20path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/ui-egui/src/menus/ui_commands.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index f1513f8df..06dcf85bc 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -1536,7 +1536,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ crate::scripts_menu::COMMAND, "Run Script", "", - "{path: a script's path as script.listInstalled gives it} run a script of the Scripts folder, as its File › Scripts item does (script.run with the file's text, under the file's name), without the warning Other Script… shows; a file that is no longer a .js or .jsx file in the folder or a subfolder at most 4 levels below it, or that is or lies behind a link or is hidden, is not run, and the menu's listing is read again", + "{path: a script's path as script.listInstalled gives it} run a script of the Scripts folder, as its File › Scripts item does (the script is checked again, then script.run runs it by its path, so its #include lines and $.evalFile read beside it), without the warning Other Script… shows; a file that is no longer a .js or .jsx file in the folder or a subfolder at most 4 levels below it, or that is or lies behind a link or is hidden, is not run, and the menu's listing is read again", ), ( "ui.checkScript",