Skip to content

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

Open
@shanecelis

Description

@shanecelis

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions