Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterate over table with functions #152

Open
jorge-jbs opened this issue Jul 17, 2017 · 0 comments
Open

Iterate over table with functions #152

jorge-jbs opened this issue Jul 17, 2017 · 0 comments

Comments

@jorge-jbs
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant