tomaka / hlua

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

Receive callback #123

Closed alanhoff closed 7 years ago

alanhoff commented 7 years ago

Hello there, I would like to know how one could receive a callback from a Lua's return value.

fn main() {
    let mut lua = hlua::Lua::new();

    lua.execute::<()>(r#"
      function callback()
        return function (a, b)
          return a + b
        end
      end
    "#).unwrap();

    let mut cb: hlua::LuaFunction<_> = lua.get("callback").unwrap();
    let value: hlua::AnyLuaValue = cb.call().unwrap();
    println!("{:?}", value);
}

The code above returns a LuaOther type unfortunately.

tomaka commented 7 years ago

You should be able to do this:

let value: hlua::LuaFunction<_> = cb.call().unwrap();

If you need a AnyLuaValue then it's unfortunately not implemented yet.

alanhoff commented 7 years ago

Got it, thx for the advice :-)