Add back typeof global

This commit is contained in:
Filip Tibell 2023-08-20 19:58:00 -05:00
parent 9b4ca94c13
commit 4412d02b34
4 changed files with 19 additions and 2 deletions

View file

@ -1,5 +1,5 @@
use mlua::prelude::*;
pub fn create(lua: &'static Lua) -> LuaResult<impl IntoLua<'_>> {
pub fn create(lua: &Lua) -> LuaResult<impl IntoLua<'_>> {
lua.create_table()
}

View file

@ -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()?;

View file

@ -0,0 +1,15 @@
use mlua::prelude::*;
use crate::roblox::datatypes::extension::RobloxUserdataTypenameExt;
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);
}
}
lua.globals().get::<_, LuaFunction>("typeof")?.call(value)
})
}

View file

@ -1,6 +1,6 @@
use mlua::prelude::*;
pub fn create(lua: &'static Lua) -> LuaResult<impl IntoLua<'_>> {
pub fn create(lua: &Lua) -> LuaResult<impl IntoLua<'_>> {
let luau_version_full = lua
.globals()
.get::<_, LuaString>("_VERSION")