From 8378d14477e0c79129b36a98e349d27091a2054a Mon Sep 17 00:00:00 2001 From: Minijackson Date: Tue, 24 Jan 2023 22:39:31 +0100 Subject: lua-bindings: defaults to 0 when parsing unset Point2D coordinate --- lua-bindings/src/lib.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lua-bindings/src/lib.rs b/lua-bindings/src/lib.rs index 2cce0f5..fb56b5a 100644 --- a/lua-bindings/src/lib.rs +++ b/lua-bindings/src/lib.rs @@ -225,8 +225,15 @@ impl TryFrom> for Point2D { fn try_from(value: LuaValue<'_>) -> Result { match value { LuaValue::Table(table) => { - let x: Float = table.get::<_, LuaValue>("x")?.try_into()?; - let y: Float = table.get::<_, LuaValue>("y")?.try_into()?; + // TODO: not really coherent with margin, which defaults to unconstrained float + let x: Float = match table.get::<_, Option>("x")? { + None => Float(CoreFloat::Fixed(0.)), + Some(f) => f.try_into()?, + }; + let y: Float = match table.get::<_, Option>("y")? { + None => Float(CoreFloat::Fixed(0.)), + Some(f) => f.try_into()?, + }; Ok(Point2D(CorePoint2D::new(x.0, y.0))) } // Create a new float from the borrow, since it might already be borrowed, with for ex. -- cgit v1.2.3