diff --git a/src/lune/globals/g_table.rs b/src/lune/globals/g_table.rs index c073bad..8c007c8 100644 --- a/src/lune/globals/g_table.rs +++ b/src/lune/globals/g_table.rs @@ -1,5 +1,5 @@ use mlua::prelude::*; -pub fn create(lua: &'static Lua) -> LuaResult> { +pub fn create(lua: &Lua) -> LuaResult> { lua.create_table() } diff --git a/src/lune/globals/mod.rs b/src/lune/globals/mod.rs index 9605aa0..48e1deb 100644 --- a/src/lune/globals/mod.rs +++ b/src/lune/globals/mod.rs @@ -5,6 +5,7 @@ use super::util::TableBuilder; mod g_table; mod print; mod require; +mod r#typeof; mod version; mod warn; @@ -14,6 +15,7 @@ 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 new file mode 100644 index 0000000..fb1099c --- /dev/null +++ b/src/lune/globals/typeof.rs @@ -0,0 +1,15 @@ +use mlua::prelude::*; + +use crate::roblox::datatypes::extension::RobloxUserdataTypenameExt; + +pub fn create(lua: &Lua) -> LuaResult> { + 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); + } + } + lua.globals().get::<_, LuaFunction>("typeof")?.call(value) + }) +} diff --git a/src/lune/globals/version.rs b/src/lune/globals/version.rs index 153350a..3f72b5c 100644 --- a/src/lune/globals/version.rs +++ b/src/lune/globals/version.rs @@ -1,6 +1,6 @@ use mlua::prelude::*; -pub fn create(lua: &'static Lua) -> LuaResult> { +pub fn create(lua: &Lua) -> LuaResult> { let luau_version_full = lua .globals() .get::<_, LuaString>("_VERSION")