summaryrefslogtreecommitdiff
path: root/tests/macros.rs
blob: fe16cc37eb2c78648275127b6f157ac5352c8de3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#![cfg(feature = "macros")]

use mlua::{chunk, Lua, Result};

#[test]
fn test_chunk_macro() -> Result<()> {
    let lua = Lua::new();

    let name = "Rustacean";
    let table = vec![1];

    let data = lua.create_table()?;
    data.raw_set("num", 1)?;

    lua.globals().set("g", 123)?;

    lua.load(chunk! {
        assert($name == "Rustacean")
        assert($table[1] == 1)
        assert($data.num == 1)
        assert(g == 123)
        s = 321
    })
    .exec()?;

    assert_eq!(lua.globals().get::<_, i32>("s")?, 321);

    Ok(())
}