mirror of
https://github.com/mlua-rs/mlua
synced 2026-06-08 16:05:43 +00:00
+5
-1
@@ -349,7 +349,11 @@ pub(crate) unsafe fn init_error_registry(state: *mut ffi::lua_State) -> Result<(
|
||||
state,
|
||||
Some(|state| {
|
||||
ffi::lua_pushcfunction(state, error_tostring);
|
||||
rawset_field(state, -2, "__tostring")
|
||||
ffi::lua_setfield(state, -2, cstr!("__tostring"));
|
||||
|
||||
// This is mostly for Luau typeof() function
|
||||
ffi::lua_pushstring(state, cstr!("error"));
|
||||
ffi::lua_setfield(state, -2, cstr!("__type"));
|
||||
}),
|
||||
)?;
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ pub(crate) unsafe fn get_internal_metatable<T: TypeKey>(state: *mut ffi::lua_Sta
|
||||
// Uses 6 stack spaces and calls checkstack.
|
||||
pub(crate) unsafe fn init_internal_metatable<T: TypeKey>(
|
||||
state: *mut ffi::lua_State,
|
||||
customize_fn: Option<fn(*mut ffi::lua_State) -> Result<()>>,
|
||||
customize_fn: Option<fn(*mut ffi::lua_State)>,
|
||||
) -> Result<()> {
|
||||
check_stack(state, 6)?;
|
||||
|
||||
@@ -62,11 +62,11 @@ pub(crate) unsafe fn init_internal_metatable<T: TypeKey>(
|
||||
ffi::lua_pushboolean(state, 0);
|
||||
rawset_field(state, -2, "__metatable")?;
|
||||
|
||||
if let Some(f) = customize_fn {
|
||||
f(state)?;
|
||||
}
|
||||
|
||||
protect_lua!(state, 1, 0, |state| {
|
||||
if let Some(f) = customize_fn {
|
||||
f(state);
|
||||
}
|
||||
|
||||
ffi::lua_rawsetp(state, ffi::LUA_REGISTRYINDEX, T::type_key());
|
||||
})?;
|
||||
|
||||
|
||||
@@ -436,5 +436,16 @@ fn test_loadstring() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_typeof_error() -> Result<()> {
|
||||
let lua = Lua::new();
|
||||
|
||||
let err = Error::runtime("just a test error");
|
||||
let res = lua.load("return typeof(...)").call::<String>(err)?;
|
||||
assert_eq!(res, "error");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[path = "luau/require.rs"]
|
||||
mod require;
|
||||
|
||||
Reference in New Issue
Block a user