From 56f6738028578b65c84d64e6e32b89f5daaab966 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Sat, 5 Oct 2024 12:35:48 -0700 Subject: [PATCH] wip ClassFunctions --- src/runner/instance.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/runner/instance.rs b/src/runner/instance.rs index 4c482d3..1afd5e9 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<&'static str,//ClassName + HashMap<&'static 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{