fix: ADD SWITCHER keyword - use register_custom_syntax instead of register_fn
The compiler outputs ADD_SWITCHER "x" as "y" format but the keyword was registered as a plain Rhai function expecting add_switcher(x, y). Changed to register_custom_syntax matching the output format, consistent with ADD_SUGGESTION and CLEAR SWITCHERS patterns. Fixes #495
This commit is contained in:
parent
28c48eeabf
commit
867c5c5be4
1 changed files with 24 additions and 15 deletions
|
|
@ -92,15 +92,24 @@ pub fn add_switcher_keyword(
|
||||||
let user_session_clone = user_session.clone();
|
let user_session_clone = user_session.clone();
|
||||||
|
|
||||||
engine
|
engine
|
||||||
.register_fn("add_switcher", move |switcher_id: &str, button_text: &str| {
|
.register_custom_syntax(
|
||||||
let result = add_switcher(
|
["ADD_SWITCHER", "$expr$", "as", "$expr$"],
|
||||||
|
true,
|
||||||
|
move |context, inputs| {
|
||||||
|
let switcher_id = context.eval_expression_tree(&inputs[0])?.to_string();
|
||||||
|
let button_text = context.eval_expression_tree(&inputs[1])?.to_string();
|
||||||
|
|
||||||
|
add_switcher(
|
||||||
cache.as_ref(),
|
cache.as_ref(),
|
||||||
&user_session_clone,
|
&user_session_clone,
|
||||||
switcher_id,
|
&switcher_id,
|
||||||
button_text,
|
&button_text,
|
||||||
);
|
)?;
|
||||||
result.map_err(|e| e.to_string())
|
|
||||||
});
|
Ok(Dynamic::UNIT)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.expect("valid syntax registration");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_switcher(
|
fn add_switcher(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue