rhaiscript / rhai

Rhai - An embedded scripting language for Rust.
https://crates.io/crates/rhai
Apache License 2.0
3.73k stars 175 forks source link

Issues about the function of print #594

Closed youngzhaozju closed 2 years ago

youngzhaozju commented 2 years ago

Hey,

I found that I cannot print ${x} message from rhai correctly. I designed many cases using the following case.

[cfg(test)]

mod tests { use rhai::{Engine, EvalAltResult};

#[test]
fn test() {}

#[test]
fn texst() {
    let mut engine = Engine::new();

    let result = engine.eval::<i64>(
        **r#"
        let a = 12.3;
         print("test1");
        1"#,**
    );
}

}

Case 1: r#" let a = 12.3; print("test1"); 1"#, result: running 1 test test1

Case 2: r#" let a = 12.3; print("test1 ${a}"); 1"#,

result: running 1 test test1 ${a}

Case 3: r#" let a = 12.3; print('test1 ${a}'); 1"#, result: Nothing

Case 4: let a = 12.3; print("test1"); print("test1 ${a}"); 1"#, result: running 1 test test1 test1 ${a}

schungx commented 2 years ago

Use back-ticks for string interpolation.

https://rhai.rs/book/language/strings-chars.html#string-interpolation

youngzhaozju commented 2 years ago

Thank you!