It can be done if there is a way to push an empty table and get both the PushGuard and LuaTable, then I can implement LuaPush for it. But I didn't find a way to do that.
Another way I tried to do it is by implement_lua_push!, which pushes a userdata with a metatable, then set my entries in __index table (like in the example). But then the table can't be iterated over by:
for k, v in pairs(tbl) do
print(k, v)
end
It will be a bad idea to ask the user to get the __index table for iteration:
for k, v in pairs(getmetatable(tbl).__index) do
print(k, v)
end
I have a function in Rust that will be called in Lua. I'd like the function to return a heterogeneous table like this:
It can be done if there is a way to push an empty table and get both the
PushGuard
andLuaTable
, then I can implementLuaPush
for it. But I didn't find a way to do that.Another way I tried to do it is by
implement_lua_push!
, which pushes a userdata with a metatable, then set my entries in__index
table (like in the example). But then the table can't be iterated over by:It will be a bad idea to ask the user to get the
__index
table for iteration: