diff --git a/src/lua/direction.rs b/src/lua/direction.rs index c58153e..6f18d51 100644 --- a/src/lua/direction.rs +++ b/src/lua/direction.rs @@ -18,9 +18,13 @@ impl IntoLua for Direction { impl FromLua for Direction { fn from_lua(value: Value, _lua: &Lua) -> Result { if let Value::Table(table) = value { - Ok(Self { - x: table.get("x")?, - y: table.get("y")?, + Ok(if let (Ok(x), Ok(y)) = (table.get(1), table.get(2)) { + Self { x, y } + } else { + Self { + x: table.get("x")?, + y: table.get("y")?, + } }) } else { Err(mlua::Error::FromLuaConversionError { diff --git a/src/lua/vec3.rs b/src/lua/vec3.rs index 4ac8385..5d8e50b 100644 --- a/src/lua/vec3.rs +++ b/src/lua/vec3.rs @@ -19,18 +19,28 @@ impl IntoLua for Vec3 { impl FromLua for Vec3 { fn from_lua(value: Value, _lua: &Lua) -> Result { - if let Value::Table(table) = value { - Ok(Self { - x: table.get("x")?, - y: table.get("y")?, - z: table.get("z")?, - }) - } else { - Err(mlua::Error::FromLuaConversionError { + match value { + Value::Table(table) => Ok( + if let (Ok(x), Ok(y), Ok(z)) = (table.get(1), table.get(2), table.get(3)) { + Self { x, y, z } + } else { + Self { + x: table.get("x")?, + y: table.get("y")?, + z: table.get("z")?, + } + }, + ), + Value::Vector(vector) => Ok(Self { + x: vector.x().into(), + y: vector.y().into(), + z: vector.z().into(), + }), + _ => Err(mlua::Error::FromLuaConversionError { from: value.type_name(), to: "Vec3".to_string(), message: None, - }) + }), } } }