mlua/tests/types.rs

39 lines
808 B
Rust
Raw Normal View History

2020-05-16 10:13:38 -04:00
#![cfg_attr(
all(feature = "luajit", target_os = "macos", target_arch = "x86_64"),
feature(link_args)
)]
#[cfg_attr(
all(feature = "luajit", target_os = "macos", target_arch = "x86_64"),
link_args = "-pagezero_size 10000 -image_base 100000000",
allow(unused_attributes)
)]
extern "system" {}
2018-02-09 23:52:05 -05:00
use std::os::raw::c_void;
2019-10-14 17:21:30 -04:00
use mlua::{Function, LightUserData, Lua, Result};
2018-02-09 23:52:05 -05:00
#[test]
2019-09-28 10:23:17 -04:00
fn test_lightuserdata() -> Result<()> {
2019-10-14 17:21:30 -04:00
let lua = Lua::new();
2019-09-28 10:23:17 -04:00
2018-02-09 23:52:05 -05:00
let globals = lua.globals();
2019-09-28 10:23:17 -04:00
lua.load(
2018-02-09 23:52:05 -05:00
r#"
2019-09-28 10:23:17 -04:00
function id(a)
return a
end
"#,
2019-09-27 12:38:24 -04:00
)
2019-09-28 10:23:17 -04:00
.exec()?;
2018-02-09 23:52:05 -05:00
let res = globals
2019-09-28 10:23:17 -04:00
.get::<_, Function>("id")?
.call::<_, LightUserData>(LightUserData(42 as *mut c_void))?;
2018-02-09 23:52:05 -05:00
assert_eq!(res, LightUserData(42 as *mut c_void));
2019-09-28 10:23:17 -04:00
Ok(())
2018-02-09 23:52:05 -05:00
}