mirror of
https://github.com/lune-org/lune.git
synced 2025-04-18 10:53:46 +01:00
Implement conversions to and from Content
This commit is contained in:
parent
d411c8f908
commit
a0710d9b3f
2 changed files with 18 additions and 7 deletions
|
@ -104,8 +104,8 @@ impl<'lua> LuaToDomValue<'lua> for LuaValue<'lua> {
|
||||||
(LuaValue::String(s), DomType::BinaryString) => {
|
(LuaValue::String(s), DomType::BinaryString) => {
|
||||||
Ok(DomValue::BinaryString(s.as_ref().into()))
|
Ok(DomValue::BinaryString(s.as_ref().into()))
|
||||||
}
|
}
|
||||||
(LuaValue::String(s), DomType::Content) => {
|
(LuaValue::String(s), DomType::ContentId) => {
|
||||||
Ok(DomValue::Content(s.to_str()?.to_string().into()))
|
Ok(DomValue::ContentId(s.to_str()?.to_string().into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: Some values are either optional or default and we
|
// NOTE: Some values are either optional or default and we
|
||||||
|
@ -200,6 +200,7 @@ impl<'lua> DomValueToLua<'lua> for LuaAnyUserData<'lua> {
|
||||||
DomValue::Color3(value) => dom_to_userdata!(lua, value => Color3),
|
DomValue::Color3(value) => dom_to_userdata!(lua, value => Color3),
|
||||||
DomValue::Color3uint8(value) => dom_to_userdata!(lua, value => Color3),
|
DomValue::Color3uint8(value) => dom_to_userdata!(lua, value => Color3),
|
||||||
DomValue::ColorSequence(value) => dom_to_userdata!(lua, value => ColorSequence),
|
DomValue::ColorSequence(value) => dom_to_userdata!(lua, value => ColorSequence),
|
||||||
|
DomValue::Content(value) => dom_to_userdata!(lua, value => Content),
|
||||||
DomValue::Faces(value) => dom_to_userdata!(lua, value => Faces),
|
DomValue::Faces(value) => dom_to_userdata!(lua, value => Faces),
|
||||||
DomValue::Font(value) => dom_to_userdata!(lua, value => Font),
|
DomValue::Font(value) => dom_to_userdata!(lua, value => Font),
|
||||||
DomValue::NumberRange(value) => dom_to_userdata!(lua, value => NumberRange),
|
DomValue::NumberRange(value) => dom_to_userdata!(lua, value => NumberRange),
|
||||||
|
@ -256,6 +257,7 @@ impl<'lua> LuaToDomValue<'lua> for LuaAnyUserData<'lua> {
|
||||||
DomType::Color3 => userdata_to_dom!(self as Color3 => dom::Color3),
|
DomType::Color3 => userdata_to_dom!(self as Color3 => dom::Color3),
|
||||||
DomType::Color3uint8 => userdata_to_dom!(self as Color3 => dom::Color3uint8),
|
DomType::Color3uint8 => userdata_to_dom!(self as Color3 => dom::Color3uint8),
|
||||||
DomType::ColorSequence => userdata_to_dom!(self as ColorSequence => dom::ColorSequence),
|
DomType::ColorSequence => userdata_to_dom!(self as ColorSequence => dom::ColorSequence),
|
||||||
|
DomType::Content => userdata_to_dom!(self as Content => dom::Content),
|
||||||
DomType::Enum => userdata_to_dom!(self as EnumItem => dom::Enum),
|
DomType::Enum => userdata_to_dom!(self as EnumItem => dom::Enum),
|
||||||
DomType::Faces => userdata_to_dom!(self as Faces => dom::Faces),
|
DomType::Faces => userdata_to_dom!(self as Faces => dom::Faces),
|
||||||
DomType::Font => userdata_to_dom!(self as Font => dom::Font),
|
DomType::Font => userdata_to_dom!(self as Font => dom::Font),
|
||||||
|
|
|
@ -102,10 +102,19 @@ impl fmt::Display for Content {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<DomContent> for Content {
|
impl From<DomContent> for Content {
|
||||||
type Error = LuaError;
|
fn from(value: DomContent) -> Self {
|
||||||
|
Self(value.value().clone())
|
||||||
fn try_from(value: DomContent) -> Result<Self, Self::Error> {
|
}
|
||||||
Ok(Self(value.value().clone()))
|
}
|
||||||
|
|
||||||
|
impl From<Content> for DomContent {
|
||||||
|
fn from(value: Content) -> Self {
|
||||||
|
match value.0 {
|
||||||
|
ContentType::None => Self::none(),
|
||||||
|
ContentType::Uri(uri) => Self::from_uri(uri),
|
||||||
|
ContentType::Object(referent) => Self::from_referent(referent),
|
||||||
|
other => unimplemented!("unknown variant of ContentType: {other:?}"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue