rhai: Custom Syntax won't work

Version 0.17.0

I was experimenting a bit with defining a custom syntax and I can’t manage to create a working custom syntax.

implementation_func

fn implementation_func(
    engine: &Engine,
    scope: &mut Scope,
    mods: &mut Imports,
    state: &mut EvalState,
    lib: &Module,
    this_ptr: &mut Option<&mut Dynamic>,
    inputs: &[Expression],
    level: usize
) -> Result<Dynamic, Box<EvalAltResult>> {
    let expression = inputs.get(0).unwrap();
    let value = engine.eval_expression_tree(scope, mods, state, lib, this_ptr, expression, level)?;

    println!("{:?}", value);

    Ok(().into())
}

main

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut engine = Engine::new();

    engine.register_custom_syntax(
        &["test", "$expr$"],
        0,
        implementation_func
    )?;

    engine
        .eval::<Dynamic>(
            r#"
            test 0;
            "#,
        )
        .unwrap();

    Ok(())
}

error

memory allocation of 443792878928 bytes failederror: process didn't exit successfully: `target\debug\wwm.exe` (exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN)

Running the code without the test 0; line results in the following error

error

error: process didn't exit successfully: `target\debug\wwm.exe` (exit code: 0xc0000374, STATUS_HEAP_CORRUPTION)

If I remove the register_custom_syntax call the program exists successfully.

The syntax I provided as an example is very simple and the resulting DSL should more look like the following code snippet.

enable work_mode;
enable launch_on_startup;

set work_mode true;
set min_height 200;

bind "Alt+Enter" to launch("wt.exe");

for i in range(1,10) {
  let key = "Alt+" + i;
  bind key to change_workspace(i);
}

mode resize {
  bind "H" to resize("Left", 2);
  bind "Shift+H" to resize("Left", -2);
};

I am try to see whether I can use rhai as the configuration language for WWM

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 20

Most upvoted comments

I noticed that I accidently evaluted the block twice. Sorry.