diff --git a/src/runner/instance.rs b/src/runner/instance.rs index fa15058..d2e12bc 100644 --- a/src/runner/instance.rs +++ b/src/runner/instance.rs @@ -1,10 +1,26 @@ +use std::collections::HashMap; + use mlua::IntoLua; use rbx_types::Ref; use rbx_dom_weak::{InstanceBuilder,WeakDom}; use super::vector3::Vector3; +/// A store of created functions for each Roblox class. +/// Functions are created the first time they are accessed and stored in this data structure. +#[derive(Default)] +struct ClassFunctions<'a>{ + classes:HashMap<&'a str,//ClassName + HashMap<&'a str,//Function name + mlua::Function<'a> + > + > +} + pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table<'_>)->Result<(),mlua::Error>{ + //class functions store + lua.set_app_data(ClassFunctions::default()); + let instance_table=lua.create_table()?; //Instance.new @@ -29,6 +45,10 @@ fn dom_mut(lua:&mlua::Lua,mut f:impl FnMut(&mut WeakDom)->mlua::Result)->m let mut dom=lua.app_data_mut::<&'static mut WeakDom>().ok_or(mlua::Error::runtime("DataModel missing"))?; f(&mut *dom) } +fn class_functions_mut(lua:&mlua::Lua,mut f:impl FnMut(&mut ClassFunctions<'_>)->mlua::Result)->mlua::Result{ + let mut dom=lua.app_data_mut::>().ok_or(mlua::Error::runtime("ClassFunctions missing"))?; + f(&mut *dom) +} fn coerce_float32(value:&mlua::Value)->Option{ match value{