Compare commits

...

2 Commits

Author SHA1 Message Date
01c603f483 multiple unsafe but it compiles 2024-10-05 16:30:46 -07:00
d4b9fd1615 hmm 2024-10-05 16:30:46 -07:00

View File

@ -1,4 +1,4 @@
use std::collections::HashMap; use std::collections::{hash_map::Entry,HashMap};
use mlua::{IntoLua,IntoLuaMulti}; use mlua::{IntoLua,IntoLuaMulti};
use rbx_types::Ref; use rbx_types::Ref;
@ -264,40 +264,42 @@ impl mlua::UserData for Instance{
//find a function with a matching name //find a function with a matching name
if let Some(ret)=class_functions_mut(lua,|cf|{ if let Some(ret)=class_functions_mut(lua,|cf|{
let class_str=instance.class.as_str(); let class_str=instance.class.as_str();
Ok(match cf.classes.entry(class_str){ let f=match CLASS_FUNCTION_DATABASE.get_entry(class_str){
std::collections::hash_map::Entry::Occupied(occupied_entry)=>{ Some((&static_class_str,class_functions))=>{
match occupied_entry.get().entry(index_str){ match cf.classes.entry(static_class_str){
std::collections::hash_map::Entry::Occupied(occupied_entry)=>{ Entry::Occupied(mut occupied_entry)=>{
Some(occupied_entry.get()) match class_functions.get_entry(index_str){
Some((&static_index_str,function_pointer))=>{
match occupied_entry.get_mut().entry(static_index_str){
Entry::Occupied(occupied_entry)=>{
Some(occupied_entry.get().clone())
},
Entry::Vacant(vacant_entry)=>{
Some(vacant_entry.insert(unsafe{core::mem::transmute(lua.create_function(function_pointer)?)}).clone())
},
}
},
None=>None,
}
}, },
std::collections::hash_map::Entry::Vacant(vacant_entry)=>{ Entry::Vacant(vacant_entry)=>{
match CLASS_FUNCTION_DATABASE.get(class_str) match class_functions.get_entry(index_str){
.and_then(|class_functions| Some((&static_index_str,function_pointer))=>{
class_functions.get(index_str) let mut h=HashMap::new();
) h.entry(static_index_str).or_insert(unsafe{core::mem::transmute(lua.create_function(function_pointer)?)});
{ vacant_entry.insert(h).get(static_index_str).map(|f|f.clone())
Some(f_pointer)=>Some(&*vacant_entry.insert(lua.create_function(f_pointer)?)), },
None=>None, None=>None,
} }
}, },
} }
}, },
std::collections::hash_map::Entry::Vacant(vacant_entry)=>{ None=>None,
match CLASS_FUNCTION_DATABASE.get(class_str) };
.and_then(|class_functions| Ok(f.map(|f|{
class_functions.get(index_str) let f_static:mlua::Function::<'static>=unsafe{core::mem::transmute(f)};
) f_static
{ }))
Some(f_pointer)=>{
let mut h=HashMap::new();
let lua_f=h.entry(index_str).or_insert(lua.create_function(f_pointer)?);
vacant_entry.insert(h);
Some(&*lua_f)
},
None=>None,
}
},
})
})?{ })?{
return Ok(ret.into_lua(lua)); return Ok(ret.into_lua(lua));
} }