diff --git a/lib/roblox_emulator/src/runner/brickcolor.rs b/lib/roblox_emulator/src/runner/brickcolor.rs index 00276df..f8fddc3 100644 --- a/lib/roblox_emulator/src/runner/brickcolor.rs +++ b/lib/roblox_emulator/src/runner/brickcolor.rs @@ -6,17 +6,43 @@ impl BrickColor{ pub fn from_name(name:&str)->Option<Self>{ Some(BrickColor(rbx_types::BrickColor::from_name(name)?)) } + pub fn from_number(number:u16)->Option<Self>{ + Some(BrickColor(rbx_types::BrickColor::from_number(number)?)) + } } pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table)->Result<(),mlua::Error>{ let table=lua.create_table()?; table.raw_set("new", - lua.create_function(|_,name:mlua::String| - Ok(BrickColor::from_name(&*name.to_str()?)) + lua.create_function(|_,r:mlua::Value| + match r{ + mlua::Value::String(name)=>Ok(BrickColor::from_name(&*name.to_str()?)), + mlua::Value::Integer(number)=>Ok(BrickColor::from_number(number as u16)), + _=>Err(mlua::Error::runtime("Unsupported arguments")) + } + )? )?; + macro_rules! brickcolor_constructor{ + ($fname:expr,$internal:ident)=>{ + table.raw_set($fname, + lua.create_function(|_,_:()| + Ok(BrickColor(rbx_types::BrickColor::$internal)) + )? + )?; + }; + } + brickcolor_constructor!("White",White); + brickcolor_constructor!("Gray",MediumStoneGrey); + brickcolor_constructor!("DarkGray",DarkStoneGrey); + brickcolor_constructor!("Black",Black); + brickcolor_constructor!("Red",BrightRed); + brickcolor_constructor!("Yellow",BrightYellow); + brickcolor_constructor!("Green",DarkGreen); + brickcolor_constructor!("Blue",BrightBlue); + globals.set("BrickColor",table)?; Ok(())