From 78593200ebc1f2aa653bfd8ec229a246fbdcee4f Mon Sep 17 00:00:00 2001
From: Quaternions <krakow20@gmail.com>
Date: Tue, 22 Apr 2025 19:15:04 -0700
Subject: [PATCH] roblox_emulator: fixup Vector3

---
 lib/roblox_emulator/src/runner/vector3.rs | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/lib/roblox_emulator/src/runner/vector3.rs b/lib/roblox_emulator/src/runner/vector3.rs
index 05430ed..288832a 100644
--- a/lib/roblox_emulator/src/runner/vector3.rs
+++ b/lib/roblox_emulator/src/runner/vector3.rs
@@ -49,23 +49,20 @@ impl mlua::UserData for Vector3{
 	fn add_methods<M:mlua::UserDataMethods<Self>>(methods:&mut M){
 		//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)|{
+		methods.add_meta_function(mlua::MetaMethod::Add,|_,(Vector3(this),Vector3(val)):(Self,Self)|Ok(Self(this+val)));
+		methods.add_meta_function(mlua::MetaMethod::Div,|_,(Vector3(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))
-				},
+				mlua::Value::Integer(n)=>Ok(Self(this/(n as f32))),
+				mlua::Value::Number(n)=>Ok(Self(this/(n as f32))),
+				mlua::Value::UserData(ud)=>ud.borrow_scoped(|Vector3(rhs):&Vector3|Self(this/rhs)),
 				other=>Err(mlua::Error::runtime(format!("Attempt to divide Vector3 by {other:?}"))),
 			}
 		});
-		methods.add_meta_function(mlua::MetaMethod::ToString,|_,this:Self|
+		methods.add_meta_function(mlua::MetaMethod::ToString,|_,Vector3(this):Self|
 			Ok(format!("Vector3.new({},{},{})",
-				this.0.x,
-				this.0.y,
-				this.0.z,
+				this.x,
+				this.y,
+				this.z,
 			))
 		);
 	}