Get rid of our custom typeof shim, thanks mlua

This commit is contained in:
Filip Tibell 2023-10-03 21:26:08 -05:00
parent 462e9a4f5a
commit e4850666c5
No known key found for this signature in database
3 changed files with 0 additions and 74 deletions

View file

@ -5,7 +5,6 @@ use super::util::TableBuilder;
mod g_table; mod g_table;
mod print; mod print;
mod require; mod require;
mod r#typeof;
mod version; mod version;
mod warn; mod warn;
@ -15,7 +14,6 @@ pub fn inject_all(lua: &'static Lua) -> LuaResult<()> {
.with_value("_VERSION", version::create(lua)?)? .with_value("_VERSION", version::create(lua)?)?
.with_value("print", print::create(lua)?)? .with_value("print", print::create(lua)?)?
.with_value("require", require::create(lua)?)? .with_value("require", require::create(lua)?)?
.with_value("typeof", r#typeof::create(lua)?)?
.with_value("warn", warn::create(lua)?)? .with_value("warn", warn::create(lua)?)?
.build_readonly()?; .build_readonly()?;

View file

@ -1,27 +0,0 @@
use mlua::prelude::*;
use crate::roblox::datatypes::extension::RobloxUserdataTypenameExt;
const REGISTRY_KEY: &str = "LuauTypeof";
pub fn create(lua: &Lua) -> LuaResult<impl IntoLua<'_>> {
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
}

View file

@ -1,7 +1,3 @@
use mlua::prelude::*;
use crate::roblox::instance::Instance;
use super::*; use super::*;
pub(crate) trait DomValueExt { pub(crate) trait DomValueExt {
@ -59,44 +55,3 @@ impl DomValueExt for DomValue {
self.ty().variant_name() 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>() => "Axes",
value if value.is::<BrickColor>() => "BrickColor",
value if value.is::<CFrame>() => "CFrame",
value if value.is::<Color3>() => "Color3",
value if value.is::<ColorSequence>() => "ColorSequence",
value if value.is::<ColorSequenceKeypoint>() => "ColorSequenceKeypoint",
value if value.is::<Enums>() => "Enums",
value if value.is::<Enum>() => "Enum",
value if value.is::<EnumItem>() => "EnumItem",
value if value.is::<Faces>() => "Faces",
value if value.is::<Font>() => "Font",
value if value.is::<Instance>() => "Instance",
value if value.is::<NumberRange>() => "NumberRange",
value if value.is::<NumberSequence>() => "NumberSequence",
value if value.is::<NumberSequenceKeypoint>() => "NumberSequenceKeypoint",
value if value.is::<PhysicalProperties>() => "PhysicalProperties",
value if value.is::<Ray>() => "Ray",
value if value.is::<Rect>() => "Rect",
value if value.is::<Region3>() => "Region3",
value if value.is::<Region3int16>() => "Region3int16",
value if value.is::<UDim>() => "UDim",
value if value.is::<UDim2>() => "UDim2",
value if value.is::<Vector2>() => "Vector2",
value if value.is::<Vector2int16>() => "Vector2int16",
value if value.is::<Vector3>() => "Vector3",
value if value.is::<Vector3int16>() => "Vector3int16",
_ => return None,
})
}
}