diff options
author | Alex Orlenko <zxteam@protonmail.com> | 2022-02-12 18:36:26 +0000 |
---|---|---|
committer | Alex Orlenko <zxteam@protonmail.com> | 2022-02-12 18:40:18 +0000 |
commit | 9a5a341e44eb28f6f78d013b1ff9162f79eff163 (patch) | |
tree | 4cb79121db993ee3fd4f19d680bdfefa76da4cf6 | |
parent | dd91ebfbe545841f0dbe8d573fd90ad6f7c41c5b (diff) | |
download | mlua-9a5a341e44eb28f6f78d013b1ff9162f79eff163.zip |
Recognize LuaJIT TCDATA type to generate correct panic message.
Relates to #127
Should be fixed in a next major release by adding support of TCDATA type.
-rw-r--r-- | src/ffi/lua.rs | 4 | ||||
-rw-r--r-- | src/ffi/mod.rs | 3 | ||||
-rw-r--r-- | src/lua.rs | 7 | ||||
-rw-r--r-- | tests/tests.rs | 21 |
4 files changed, 35 insertions, 0 deletions
diff --git a/src/ffi/lua.rs b/src/ffi/lua.rs index 12ec1cc..f96b989 100644 --- a/src/ffi/lua.rs +++ b/src/ffi/lua.rs @@ -101,6 +101,10 @@ pub const LUA_TFUNCTION: c_int = 6; pub const LUA_TUSERDATA: c_int = 7; pub const LUA_TTHREAD: c_int = 8; +// Type produced by LuaJIT FFI module +#[cfg(feature = "luajit")] +pub const LUA_TCDATA: c_int = 10; + #[cfg(feature = "lua54")] pub const LUA_NUMTYPES: c_int = 9; #[cfg(any(feature = "lua53", feature = "lua52"))] diff --git a/src/ffi/mod.rs b/src/ffi/mod.rs index c166ca6..0f49697 100644 --- a/src/ffi/mod.rs +++ b/src/ffi/mod.rs @@ -236,6 +236,9 @@ pub use self::lua::LUA_ERRGCMM; #[cfg(any(feature = "lua51", feature = "luajit"))] pub use self::lua::{LUA_ENVIRONINDEX, LUA_GLOBALSINDEX}; +#[cfg(feature = "luajit")] +pub use self::lua::LUA_TCDATA; + // constants from lauxlib.h pub use self::lauxlib::{LUA_ERRFILE, LUA_NOREF, LUA_REFNIL}; @@ -1988,6 +1988,13 @@ impl Lua { ffi::LUA_TTHREAD => Value::Thread(Thread(self.pop_ref())), + #[cfg(feature = "luajit")] + ffi::LUA_TCDATA => { + ffi::lua_pop(state, 1); + // TODO: Fix this in a next major release + panic!("cdata objects cannot be handled by mlua yet"); + } + _ => mlua_panic!("LUA_TNONE in pop_value"), } } diff --git a/tests/tests.rs b/tests/tests.rs index 95c41ad..4b92d4f 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1256,3 +1256,24 @@ fn test_warnings() -> Result<()> { Ok(()) } + +#[test] +#[cfg(feature = "luajit")] +#[should_panic] +fn test_luajit_cdata() { + let lua = unsafe { Lua::unsafe_new() }; + let _v: Result<Value> = lua + .load( + r#" + local ffi = require("ffi") + ffi.cdef[[ + void *malloc(size_t size); + void free(void *ptr); + ]] + local ptr = ffi.C.malloc(1) + ffi.C.free(ptr) + return ptr + "#, + ) + .eval(); +} |