mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 13:00:37 +00:00
Fix custom typeof function being recursivve
This commit is contained in:
parent
02c9bce645
commit
1baf10fa87
1 changed files with 20 additions and 8 deletions
|
@ -2,14 +2,26 @@ use mlua::prelude::*;
|
|||
|
||||
use crate::roblox::datatypes::extension::RobloxUserdataTypenameExt;
|
||||
|
||||
const REGISTRY_KEY: &str = "NetClient";
|
||||
|
||||
pub fn create(lua: &Lua) -> LuaResult<impl IntoLua<'_>> {
|
||||
lua.create_function(|lua, value: LuaValue| {
|
||||
#[cfg(feature = "roblox")]
|
||||
if let LuaValue::UserData(u) = &value {
|
||||
if let Some(type_name) = u.roblox_type_name() {
|
||||
return lua.create_string(type_name);
|
||||
let original = lua.globals().get::<_, LuaFunction>("typeof")?;
|
||||
#[cfg(feature = "roblox")]
|
||||
{
|
||||
lua.set_named_registry_value(REGISTRY_KEY, original)
|
||||
.expect("Failed to store typeof function in registry");
|
||||
lua.create_function(|lua, value: LuaValue| {
|
||||
if let LuaValue::UserData(u) = &value {
|
||||
if let Some(type_name) = u.roblox_type_name() {
|
||||
return lua.create_string(type_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
lua.globals().get::<_, LuaFunction>("typeof")?.call(value)
|
||||
})
|
||||
let original_fn: LuaFunction = lua
|
||||
.named_registry_value(REGISTRY_KEY)
|
||||
.expect("Missing typeof function in registry");
|
||||
original_fn.call(value)
|
||||
})
|
||||
}
|
||||
#[cfg(not(feature = "roblox"))]
|
||||
original
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue