add some Color3 methods
This commit is contained in:
parent
eccf7243c4
commit
ff9c122470
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user