root.keys(): Fix query when no keys are defined
When just running root.keys() as the first thing in Lua, it should
return an empty table. However, before this commit it would throw an
error, because no keys were set yet.
@@ -110,7 +110,7 @@ fn root_keys<'lua>(lua: &'lua Lua, key_array: rlua::Value) -> rlua::Result<rlua:
Value::Nil => {
// NOTE We make a deep clone so they can't modify references.
let res = lua.create_table()?;
- for entry in lua.globals().get::<_, Table>(ROOT_KEYS_HANDLE)?.pairs() {
+ for entry in lua.globals().get::<_, Table>(ROOT_KEYS_HANDLE).or(lua.create_table())?.pairs() {
let (key, value) = entry?;
res.set::<Value, Value>(key, value)?;
}
