From 7780e1a3f1532bf10b8d0371e6d6cd3b3866bd2a Mon Sep 17 00:00:00 2001 From: Quaternions Date: Sat, 28 Sep 2024 12:31:41 -0700 Subject: [PATCH] Vector3 __div --- src/runner/vector3.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/runner/vector3.rs b/src/runner/vector3.rs index 36aee3e..2e1942d 100644 --- a/src/runner/vector3.rs +++ b/src/runner/vector3.rs @@ -37,6 +37,17 @@ impl mlua::UserData for Vector3{ //methods.add_method("area",|_,this,()| Ok(this.length * this.width)); methods.add_meta_function(mlua::MetaMethod::Add,|_,(this,val):(Self,Self)|Ok(Self(this.0+val.0))); + methods.add_meta_function(mlua::MetaMethod::Div,|_,(this,val):(Self,mlua::Value)|{ + match val{ + mlua::Value::Integer(n)=>Ok(Self(this.0/(n as f32))), + mlua::Value::Number(n)=>Ok(Self(this.0/(n as f32))), + mlua::Value::UserData(ud)=>{ + let rhs:Vector3=ud.take()?; + Ok(Self(this.0/rhs.0)) + }, + other=>Err(mlua::Error::runtime(format!("Attempt to divide Vector3 by {other:?}"))), + } + }); methods.add_meta_function(mlua::MetaMethod::ToString,|_,this:Self| Ok(format!("Vector3.new({},{},{})", this.0.x,