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

Fill operator #435

Open
K4rakara opened this issue Feb 13, 2021 · 1 comment
Open

Fill operator #435

K4rakara opened this issue Feb 13, 2021 · 1 comment

Comments

@K4rakara
Copy link

K4rakara commented Feb 13, 2021

A nice feature to have would be JavaScripts fill operator:

const object1 = { foo: "Hello", bar: "World" } // { foo: "Hello", bar: "World" }
const object2 = { ...object1, bar: "Universe" } // { foo: "Hello", bar: "Universe" }

Now, ... in lua is an operator(?) that copies variable arguments, if they exist.

So, something else would have to be used; heres a few options:

  • ,,, table1:
    • pros: Simple, close to what you would type for ....
    • cons: Looks weird
  • .. table1: Could be used if it is only allowed in situations where there is nothing before the .. operator except for { or ,.
    • pros: Simple, similar to something Lua would do, close to what you would type for ....
    • cons: might clash with the concat operator if not implemented right.

As far as what this could compile to, its fairly simple:

table1 = { foo: "Hello", bar: "World" }
table2 = { ..table1, bar: "Universe" }

Becomes:

table1 = { foo = "Hello", bar = "World" }
table2 = { table.unpack(table1), bar = "Universe" }
@tommy-mor
Copy link

i would like this

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

2 participants