ClassFunction exceptional simplification
This commit is contained in:
parent
082de122b1
commit
726ffeca21
@ -1,4 +1,4 @@
|
|||||||
use std::collections::{hash_map::Entry,HashMap};
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use mlua::{FromLua,FromLuaMulti,IntoLua,IntoLuaMulti};
|
use mlua::{FromLua,FromLuaMulti,IntoLua,IntoLuaMulti};
|
||||||
use rbx_types::Ref;
|
use rbx_types::Ref;
|
||||||
@ -384,43 +384,21 @@ struct ClassFunctions{
|
|||||||
>
|
>
|
||||||
}
|
}
|
||||||
impl ClassFunctions{
|
impl ClassFunctions{
|
||||||
/// Someone please rewrite this, all it's supposed to do is
|
|
||||||
/// return self.classes[class][index] or create the function in the hashmap and then return it
|
/// return self.classes[class][index] or create the function in the hashmap and then return it
|
||||||
fn get_or_create_class_function(&mut self,lua:&mlua::Lua,class:&str,index:&str)->mlua::Result<Option<mlua::Function>>{
|
fn get_or_create_class_function(&mut self,lua:&mlua::Lua,class:&str,index:&str)->mlua::Result<Option<mlua::Function>>{
|
||||||
// Use get_entry to get the &'static str key of the database
|
// Use get_entry to get the &'static str keys of the database
|
||||||
// and use it as a key for the classes hashmap
|
// and use it as a key for the classes hashmap
|
||||||
let f=match CLASS_FUNCTION_DATABASE.get_entry(class){
|
if let Some((&static_class_str,class_functions))=CLASS_FUNCTION_DATABASE.get_entry(class){
|
||||||
Some((&static_class_str,class_functions))=>{
|
if let Some((&static_index_str,function_pointer))=class_functions.get_entry(index){
|
||||||
match self.classes.entry(static_class_str){
|
return Ok(Some(
|
||||||
Entry::Occupied(mut occupied_entry)=>{
|
self.classes.entry(static_class_str)
|
||||||
match class_functions.get_entry(index){
|
.or_insert_with(||HashMap::new())
|
||||||
Some((&static_index_str,function_pointer))=>{
|
.entry(static_index_str)
|
||||||
match occupied_entry.get_mut().entry(static_index_str){
|
.or_insert(lua.create_function(function_pointer)?)
|
||||||
Entry::Occupied(occupied_entry)=>{
|
.clone()
|
||||||
Some(occupied_entry.get().clone())
|
))
|
||||||
},
|
}
|
||||||
Entry::Vacant(vacant_entry)=>{
|
}
|
||||||
Some(vacant_entry.insert(lua.create_function(function_pointer)?).clone())
|
return Ok(None)
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None=>None,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Entry::Vacant(vacant_entry)=>{
|
|
||||||
match class_functions.get_entry(index){
|
|
||||||
Some((&static_index_str,function_pointer))=>{
|
|
||||||
let mut h=HashMap::new();
|
|
||||||
h.entry(static_index_str).or_insert(lua.create_function(function_pointer)?);
|
|
||||||
vacant_entry.insert(h).get(static_index_str).map(|f|f.clone())
|
|
||||||
},
|
|
||||||
None=>None,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None=>None,
|
|
||||||
};
|
|
||||||
Ok(f)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user