Skip to content

Add ScriptValue::Tuple(Vec<ScriptValue>) variant. #420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
shanecelis opened this issue May 21, 2025 · 0 comments
Open

Add ScriptValue::Tuple(Vec<ScriptValue>) variant. #420

shanecelis opened this issue May 21, 2025 · 0 comments

Comments

@shanecelis
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant