drawin_geometry: Make argument optional
In awesome, the implementation uses lua_gettop() to check how many
arguments were actually provided. I don't see how this is possible with
rlua, so instead this checks if the second argument is nil.
@@ -169,8 +169,10 @@ fn get_visible<'lua>(_: &'lua Lua, table: Table<'lua>) -> rlua::Result<bool> {
// TODO signal
}
-fn drawin_geometry<'lua>(lua: &'lua Lua, (drawin, geometry): (Table<'lua>, Table<'lua>)) -> rlua::Result<Table<'lua>> {
+fn drawin_geometry<'lua>(lua: &'lua Lua, (drawin, geometry): (Table<'lua>, Value<'lua>)) -> rlua::Result<Table<'lua>> {
let mut drawin = Drawin::cast(drawin.into())?;
+ match geometry {
+ rlua::Value::Table(geometry) => {
let w = geometry.get::<_, i32>("width")?;
let h = geometry.get::<_, i32>("height")?;
let x = geometry.get::<_, i32>("x")?;
@@ -182,6 +184,10 @@ fn drawin_geometry<'lua>(lua: &'lua Lua, (drawin, geometry): (Table<'lua>, Table
};
drawin.resize(geo)?;
}
+ },
+ rlua::Value::Nil => {},
+ _ => return Err(rlua::Error::RuntimeError("Invalid argument".to_owned()))
+ }
let new_geo = drawin.get_geometry()?;
let Size { w, h } = new_geo.size;
let Point { x, y } = new_geo.origin;
