Closed mkpankov closed 7 years ago
I'm trying to implement object-oriented access to my custom type like described here. I want to be able to do foo:bar(args) in Lua, where bar is a Rust function and foo is userdata.
foo:bar(args)
bar
foo
I thought I could set __index like so:
__index
implement_lua_push!(SerialPortLua, |mut metatable| { metatable.set("__index", XXX); });
but the problem is metatable.set accepts a hlua::function, not hlua::LuaTable.
metatable.set
hlua::function
hlua::LuaTable
Is there any other way? Maybe I'm missing something and index metatable should be set differently?
You're supposed to call metatable.empty_array("__index"), which will return a LuaTable which you can then fill.
metatable.empty_array("__index")
LuaTable
Thanks!
I'm trying to implement object-oriented access to my custom type like described here. I want to be able to do
foo:bar(args)
in Lua, wherebar
is a Rust function andfoo
is userdata.I thought I could set
__index
like so:but the problem is
metatable.set
accepts ahlua::function
, nothlua::LuaTable
.Is there any other way? Maybe I'm missing something and index metatable should be set differently?