diff --git a/src/runner/color3.rs b/src/runner/color3.rs index fb155b8..7952a89 100644 --- a/src/runner/color3.rs +++ b/src/runner/color3.rs @@ -33,11 +33,36 @@ pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table<'_>)->Result<(),mlua::Err Ok(()) } +fn lerp(lhs:f32,rhs:f32,t:f32)->f32{ + lhs+(rhs-lhs)*t +} impl mlua::UserData for Color3{ fn add_fields<'lua,F:mlua::UserDataFields<'lua,Self>>(fields:&mut F){ + fields.add_field_method_get("r",|_,this|Ok(this.r)); + fields.add_field_method_set("r",|_,this,val|{ + this.r=val; + Ok(()) + }); + fields.add_field_method_get("g",|_,this|Ok(this.g)); + fields.add_field_method_set("g",|_,this,val|{ + this.g=val; + Ok(()) + }); + fields.add_field_method_get("b",|_,this|Ok(this.b)); + fields.add_field_method_set("b",|_,this,val|{ + this.b=val; + Ok(()) + }); } fn add_methods<'lua,M:mlua::UserDataMethods<'lua,Self>>(methods:&mut M){ + methods.add_method("Lerp",|_,this,(other,t):(Self,f32)| + Ok(Color3::new( + lerp(this.r,other.r,t), + lerp(this.g,other.g,t), + lerp(this.b,other.b,t), + )) + ) } } type_from_lua_userdata!(Color3); diff --git a/src/runner/vector3.rs b/src/runner/vector3.rs index ef47f2f..7b33eec 100644 --- a/src/runner/vector3.rs +++ b/src/runner/vector3.rs @@ -35,21 +35,21 @@ impl From for Vector3{ } impl mlua::UserData for Vector3{ - fn add_fields<'lua,F: mlua::UserDataFields<'lua,Self>>(fields: &mut F) { - fields.add_field_method_get("magnitude",|_,this| Ok(this.0.length())); - fields.add_field_method_get("x",|_,this| Ok(this.0.x)); - fields.add_field_method_set("x",|_,this,val| { - this.0.x = val; + fn add_fields<'lua,F: mlua::UserDataFields<'lua,Self>>(fields: &mut F){ + fields.add_field_method_get("magnitude",|_,this|Ok(this.0.length())); + fields.add_field_method_get("x",|_,this|Ok(this.0.x)); + fields.add_field_method_set("x",|_,this,val|{ + this.0.x=val; Ok(()) }); - fields.add_field_method_get("y",|_,this| Ok(this.0.y)); - fields.add_field_method_set("y",|_,this,val| { - this.0.y = val; + fields.add_field_method_get("y",|_,this|Ok(this.0.y)); + fields.add_field_method_set("y",|_,this,val|{ + this.0.y=val; Ok(()) }); - fields.add_field_method_get("z",|_,this| Ok(this.0.z)); - fields.add_field_method_set("z",|_,this,val| { - this.0.z = val; + fields.add_field_method_get("z",|_,this|Ok(this.0.z)); + fields.add_field_method_set("z",|_,this,val|{ + this.0.z=val; Ok(()) }); }