Skip to content

Allow other types of keys in renameable table destructuring feature #134

Description

@Lyrth

Clue supports renameable destructuring - local {a => b} = t read as "assign t.a to local b" - but currently only identifier fields are allowed (names that can index tables through dot notation).

It would be nice if we can also use value types for the source field, similar to Lua letting you use any non-nil type as a table key.

local {[1] => a, [2] => b} = {"hello", "world"}
// -- now a is "hello" and b is "world"

local {[true] => c, ["string field"] => d} = {[true] = false, ["string field"] = "yes"}
// -- c is now false, d is now "yes"

Better too if the source key will support expressions in general

local {[4] => {[iter] => x, [iter+1] => y}} = points
// -- x would be the value of points[4][iter], y would be points[4][iter+1]

Additionally, a separate syntax for destructuring arrays sequential-index tables may be helpful too

local [x,y,z] = {1, 0, 64}
// -- x = 1, y = 0, z = 64

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions