hlua
hlua copied to clipboard
Iterate over table with functions
I am trying to iterate over a table with functions unsuccessfully. I am not very experienced in Rust so I do not understand the compiler error. Here is my code:
let mut lua = lua::Lua::new();
lua.execute::<()>("table = { a = function (x) return x end }");
let mut fns: Vec<lua::LuaFunction<_>> = Vec::new();
let mut table_lua = lua.get::<lua::LuaTable<_>, _>("table").expect("reading table");
let mut table_lua_iter = table_lua.iter::<lua::AnyLuaValue, lua::LuaFunction<_>>();
loop {
match table_lua_iter.next() {
Some(Some((lua::AnyLuaValue::LuaString(k), v))) => {
fns.push(v);
}
None | Some(None) => break,
_ => {},
}
}
and the error message:
error: no method named `next` found for type `lua::LuaTableIterator<'_, lua::PushGuard<&mut lua::Lua<'_>>, lua::AnyLuaValue, lua::LuaFunction<_>>` in the current scope
--> src/config.rs:94:34
|
94 | match table_lua_iter.next() {
| ^^^^
|
= note: the method `next` exists but the following trait bounds were not satisfied: `lua::LuaFunction<_> : lua::LuaRead<&'i mut &'j mut lua::LuaTableIterator<lua::PushGuard<&mut lua::Lua<'_>>, lua::AnyLuaValue, lua::LuaFunction<_>>>`
I thought LuaFunction implemented LuaRead but it is not working.