wip ClassFunctions

This commit is contained in:
Quaternions 2024-10-05 12:35:48 -07:00
parent 465d1cf29d
commit 75c868df2c

View File

@ -1,10 +1,26 @@
use std::collections::HashMap;
use mlua::IntoLua; use mlua::IntoLua;
use rbx_types::Ref; use rbx_types::Ref;
use rbx_dom_weak::{InstanceBuilder,WeakDom}; use rbx_dom_weak::{InstanceBuilder,WeakDom};
use super::vector3::Vector3; 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>{ 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()?; let instance_table=lua.create_table()?;
//Instance.new //Instance.new
@ -29,6 +45,10 @@ fn dom_mut<T>(lua:&mlua::Lua,mut f:impl FnMut(&mut WeakDom)->mlua::Result<T>)->m
let mut dom=lua.app_data_mut::<&'static mut WeakDom>().ok_or(mlua::Error::runtime("DataModel missing"))?; let mut dom=lua.app_data_mut::<&'static mut WeakDom>().ok_or(mlua::Error::runtime("DataModel missing"))?;
f(&mut *dom) f(&mut *dom)
} }
fn class_functions_mut<T>(lua:&mlua::Lua,mut f:impl FnMut(&mut ClassFunctions<'_>)->mlua::Result<T>)->mlua::Result<T>{
let mut dom=lua.app_data_mut::<ClassFunctions<'static>>().ok_or(mlua::Error::runtime("ClassFunctions missing"))?;
f(&mut *dom)
}
fn coerce_float32(value:&mlua::Value)->Option<f32>{ fn coerce_float32(value:&mlua::Value)->Option<f32>{
match value{ match value{