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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#![cfg(feature = "luau")]
use std::env;
use std::fs;
use mlua::{Lua, Result, Value};
#[test]
fn test_require() -> Result<()> {
let lua = Lua::new();
let temp_dir = tempfile::tempdir().unwrap();
fs::write(
temp_dir.path().join("module.luau"),
r#"
counter = counter or 0
return counter + 1
"#,
)?;
env::set_var("LUAU_PATH", temp_dir.path().join("?.luau"));
lua.load(
r#"
local module = require("module")
assert(module == 1)
module = require("module")
assert(module == 1)
"#,
)
.exec()
}
#[test]
fn test_vectors() -> Result<()> {
let lua = Lua::new();
let globals = lua.globals();
globals.set(
"vector",
lua.create_function(|_, (x, y, z)| Ok(Value::Vector(x, y, z)))?,
)?;
let v: [f32; 3] = lua
.load("return vector(1, 2, 3) + vector(3, 2, 1)")
.eval()?;
assert_eq!(v, [4.0, 4.0, 4.0]);
Ok(())
}
|