mirror of
https://github.com/lune-org/lune.git
synced 2025-05-04 10:43:57 +01:00
Implement FromLua for Color3 and EnumItem
This commit is contained in:
parent
74cdacdeb2
commit
5aa9e53c64
2 changed files with 28 additions and 0 deletions
|
@ -108,6 +108,20 @@ impl LuaExportsTable<'_> for Color3 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'lua> FromLua<'lua> for Color3 {
|
||||||
|
fn from_lua(value: LuaValue<'lua>, _: &'lua Lua) -> LuaResult<Self> {
|
||||||
|
if let LuaValue::UserData(ud) = value {
|
||||||
|
Ok(*ud.borrow::<Color3>()?)
|
||||||
|
} else {
|
||||||
|
Err(LuaError::FromLuaConversionError {
|
||||||
|
from: value.type_name(),
|
||||||
|
to: "userdata",
|
||||||
|
message: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl LuaUserData for Color3 {
|
impl LuaUserData for Color3 {
|
||||||
fn add_fields<'lua, F: LuaUserDataFields<'lua, Self>>(fields: &mut F) {
|
fn add_fields<'lua, F: LuaUserDataFields<'lua, Self>>(fields: &mut F) {
|
||||||
fields.add_field_method_get("R", |_, this| Ok(this.r));
|
fields.add_field_method_get("R", |_, this| Ok(this.r));
|
||||||
|
|
|
@ -74,6 +74,20 @@ impl LuaUserData for EnumItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'lua> FromLua<'lua> for EnumItem {
|
||||||
|
fn from_lua(value: LuaValue<'lua>, _: &'lua Lua) -> LuaResult<Self> {
|
||||||
|
if let LuaValue::UserData(ud) = value {
|
||||||
|
Ok(ud.borrow::<EnumItem>()?.to_owned())
|
||||||
|
} else {
|
||||||
|
Err(LuaError::FromLuaConversionError {
|
||||||
|
from: value.type_name(),
|
||||||
|
to: "userdata",
|
||||||
|
message: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Display for EnumItem {
|
impl fmt::Display for EnumItem {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "{}.{}", self.parent, self.name)
|
write!(f, "{}.{}", self.parent, self.name)
|
||||||
|
|
Loading…
Add table
Reference in a new issue