From 849b0813b9ff6057fd9b1fcb501dea3c562ff2f5 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Sat, 5 Oct 2024 22:03:51 -0700 Subject: [PATCH] change cf macro to include Instance as the first argument --- src/runner/instance.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/runner/instance.rs b/src/runner/instance.rs index d0d1a77..2129f7c 100644 --- a/src/runner/instance.rs +++ b/src/runner/instance.rs @@ -333,16 +333,20 @@ impl mlua::UserData for Instance{ /// A class function definition shorthand. macro_rules! cf{ ($f:expr)=>{ - |lua,this|$f(lua,FromLuaMulti::from_lua_multi(this,lua)?)?.into_lua_multi(lua) + |lua,args|{ + //TODO: make this not suck. two fully general conversions? really? + let (this,args):(Instance,mlua::MultiValue)=FromLuaMulti::from_lua_multi(args,lua)?; + $f(lua,this,FromLuaMulti::from_lua_multi(args,lua)?)?.into_lua_multi(lua) + } }; } -type FPointer=fn(&mlua::Lua,mlua::MultiValue)->mlua::Result; +type ClassFunctionPointer=fn(&mlua::Lua,mlua::MultiValue)->mlua::Result; // TODO: use macros to define these with better organization /// A double hash map of function pointers. /// The class tree is walked by the Instance.__index metamethod to find available class methods. -static CLASS_FUNCTION_DATABASE:phf::Map<&str,phf::Map<&str,FPointer>>=phf::phf_map!{ +static CLASS_FUNCTION_DATABASE:phf::Map<&str,phf::Map<&str,ClassFunctionPointer>>=phf::phf_map!{ "DataModel"=>phf::phf_map!{ - "GetService"=>cf!(|lua,(_this,service):(Instance,mlua::String)|{ + "GetService"=>cf!(|lua,_this,service:mlua::String|{ dom_mut(lua,|dom|{ //dom.root_ref()==this.referent ? match &*service.to_str()?{ @@ -360,7 +364,7 @@ static CLASS_FUNCTION_DATABASE:phf::Map<&str,phf::Map<&str,FPointer>>=phf::phf_m }), }, "Terrain"=>phf::phf_map!{ - "FillBlock"=>cf!(|_lua,_:(Instance,super::cframe::CFrame,Vector3,super::r#enum::Enum)|mlua::Result::Ok(())) + "FillBlock"=>cf!(|_lua,_,_:(super::cframe::CFrame,Vector3,super::r#enum::Enum)|mlua::Result::Ok(())) }, };