tomaka / hlua

Rust library to interface with Lua
MIT License
507 stars 48 forks source link

Accept LuaTable as function argument? #154

Closed mkpankov closed 7 years ago

mkpankov commented 7 years ago

This code, when added as test to lua_tables.rs, fails to compile:

    #[test]
    fn accepting_luatable_as_fn_arg_works() {
        let mut lua = Lua::new();
        let foo = {
            move |config: LuaTable<_>| for (k, v) in
                config.iter::<String, String>().filter_map(|e| e)
            {
                println!("{} => {}", k, v);
            }
        };
        lua.set("foo", ::function1(foo));
    }

with this error:

   Compiling hlua v0.3.1 (file:///home/mkpankov/workspace/projects/hlua/hlua)
error[E0277]: the trait bound `for<'p> lua_tables::LuaTable<_>: LuaRead<&'p mut functions_write::InsideCallback>` is not satisfied
   --> src/lua_tables.rs:668:13
    |
668 |         lua.set("foo", ::function1(foo));
    |             ^^^ the trait `for<'p> LuaRead<&'p mut functions_write::InsideCallback>` is not implemented for `lua_tables::LuaTable<_>`
    |
    = help: the following implementations were found:
              <lua_tables::LuaTable<L> as LuaRead<L>>
    = note: required because of the requirements on the impl of `for<'p> LuaRead<&'p mut functions_write::InsideCallback>` for `(lua_tables::LuaTable<_>,)`
    = note: required because of the requirements on the impl of `for<'a> PushOne<&'a mut Lua<'_>>` for `functions_write::Function<[closure@src/lua_tables.rs:662:13: 666:14], (lua_tables::LuaTable<_>,), ()>`

Is it possible at all?

tomaka commented 7 years ago

That's unfortunately indirectly what #118 wanted to fix. Right now it's more or less waiting for ATCs/HKTs to be stable.

mkpankov commented 7 years ago

Ok, closing as there's already a [WIP] PR.

mkpankov commented 7 years ago

Not sure how #118 is blocked on ATC, but I just wanted to give a heads up: ATCs are stabilized in 1.20.