From e4850666c59e3e2139d8a687877445cdda8f6db3 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Tue, 3 Oct 2023 21:26:08 -0500 Subject: [PATCH] Get rid of our custom typeof shim, thanks mlua --- src/lune/globals/mod.rs | 2 -- src/lune/globals/typeof.rs | 27 ------------------- src/roblox/datatypes/extension.rs | 45 ------------------------------- 3 files changed, 74 deletions(-) delete mode 100644 src/lune/globals/typeof.rs diff --git a/src/lune/globals/mod.rs b/src/lune/globals/mod.rs index 48e1deb..9605aa0 100644 --- a/src/lune/globals/mod.rs +++ b/src/lune/globals/mod.rs @@ -5,7 +5,6 @@ use super::util::TableBuilder; mod g_table; mod print; mod require; -mod r#typeof; mod version; mod warn; @@ -15,7 +14,6 @@ pub fn inject_all(lua: &'static Lua) -> LuaResult<()> { .with_value("_VERSION", version::create(lua)?)? .with_value("print", print::create(lua)?)? .with_value("require", require::create(lua)?)? - .with_value("typeof", r#typeof::create(lua)?)? .with_value("warn", warn::create(lua)?)? .build_readonly()?; diff --git a/src/lune/globals/typeof.rs b/src/lune/globals/typeof.rs deleted file mode 100644 index f4f4631..0000000 --- a/src/lune/globals/typeof.rs +++ /dev/null @@ -1,27 +0,0 @@ -use mlua::prelude::*; - -use crate::roblox::datatypes::extension::RobloxUserdataTypenameExt; - -const REGISTRY_KEY: &str = "LuauTypeof"; - -pub fn create(lua: &Lua) -> LuaResult> { - 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); - } - } - 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 -} diff --git a/src/roblox/datatypes/extension.rs b/src/roblox/datatypes/extension.rs index aea0b59..4585957 100644 --- a/src/roblox/datatypes/extension.rs +++ b/src/roblox/datatypes/extension.rs @@ -1,7 +1,3 @@ -use mlua::prelude::*; - -use crate::roblox::instance::Instance; - use super::*; pub(crate) trait DomValueExt { @@ -59,44 +55,3 @@ impl DomValueExt for DomValue { self.ty().variant_name() } } - -pub trait RobloxUserdataTypenameExt { - fn roblox_type_name(&self) -> Option<&'static str>; -} - -impl<'lua> RobloxUserdataTypenameExt for LuaAnyUserData<'lua> { - #[rustfmt::skip] - fn roblox_type_name(&self) -> Option<&'static str> { - use super::types::*; - - Some(match self { - value if value.is::() => "Axes", - value if value.is::() => "BrickColor", - value if value.is::() => "CFrame", - value if value.is::() => "Color3", - value if value.is::() => "ColorSequence", - value if value.is::() => "ColorSequenceKeypoint", - value if value.is::() => "Enums", - value if value.is::() => "Enum", - value if value.is::() => "EnumItem", - value if value.is::() => "Faces", - value if value.is::() => "Font", - value if value.is::() => "Instance", - value if value.is::() => "NumberRange", - value if value.is::() => "NumberSequence", - value if value.is::() => "NumberSequenceKeypoint", - value if value.is::() => "PhysicalProperties", - value if value.is::() => "Ray", - value if value.is::() => "Rect", - value if value.is::() => "Region3", - value if value.is::() => "Region3int16", - value if value.is::() => "UDim", - value if value.is::() => "UDim2", - value if value.is::() => "Vector2", - value if value.is::() => "Vector2int16", - value if value.is::() => "Vector3", - value if value.is::() => "Vector3int16", - _ => return None, - }) - } -}