Skip to content
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

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

Open
Lyrth opened this issue Nov 23, 2023 · 1 comment
Open

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

Lyrth opened this issue Nov 23, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@Lyrth
Copy link

Lyrth commented Nov 23, 2023

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
@Maiori44 Maiori44 self-assigned this Nov 23, 2023
@Maiori44 Maiori44 added the enhancement New feature or request label Nov 23, 2023
@Maiori44 Maiori44 added this to the 4.0 milestone Nov 23, 2023
@Maiori44 Maiori44 moved this to Unsure in Update 4.0 Nov 30, 2023
@Maiori44 Maiori44 removed this from the 4.0 milestone Nov 30, 2023
@Maiori44 Maiori44 moved this from Unsure to In Progress in Update 4.0 Dec 13, 2023
@Maiori44
Copy link
Member

[...] keys in destructuring was added, but the array destructuring would need to work too differently to be simply added to table destructuring, and would have to be added as its own thing...
unless I find a way.

Maiori44 added a commit that referenced this issue Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: In Progress
Development

No branches or pull requests

2 participants