Add ScriptValue::Tuple(Vec<ScriptValue>) variant.
Problem
Some Lua APIs can pass back multiple values that are not a list. They may look like this:
x, y = cursor()
Currently one can't implement this in Rust.
Solution
What I'd suggest is to add a variant to ScriptValue called Tuple(Vec<ScriptValue>) which holds the same data type as ScriptValue::List then pass back the multiple values.
Work Around
The work around I've used is to implement _cursor() in Rust that returns a list and then in Lua add the following function:
function cursor()
local l = _cursor()
return l[1], l[2]
end
Considerations
I don't know if Lua is the only supported language that supports multiple return values. But one would need a policy on what to do if the language does not support it. I'd suggest languages that don't support multiple return values should treat ScriptValue::List and ScriptValue::Tuple the same.
I'm fully in support, I also need something like this.
My current workaround for this is for Rust code to return a Rust tuple, and then call table.unpack in Lua (further shortened to unpack in Luau):
# Rust
return (true, false);
-- Luau
local a, b = unpack(my_rust_fn())
Using unpack is a bit more ergonomic than creating an explicit destructuring function.