Skip to content

Add LuaMap and LuaSet language extensions#1303

Merged
Perryvw merged 7 commits intoTypeScriptToLua:masterfrom
GlassBricks:lua-set
Jul 14, 2022
Merged

Add LuaMap and LuaSet language extensions#1303
Perryvw merged 7 commits intoTypeScriptToLua:masterfrom
GlassBricks:lua-set

Conversation

@GlassBricks
Copy link
Copy Markdown
Contributor

Adds LuaMap and LuaSet language extensions. Readonly variants are also declared. They somewhat mimic ES maps and sets.

LuaMap is like a table, except that the get method may return nil. This more closely matches the ES map interface.

For LuaSet, two language extensions are added:

  • LuaTableAdd which translates calls of table.add(foo) to table[foo] = true
  • LuaPairsKeyIterable, which is like LuaPairsIterable except only the key value is used (and multi-return is not used).

node
)
);
return lua.createNilLiteral();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any thoughts on returning table instead? This is how sets work in TS:

const myset = new Set<number>().add(1).add(2).add(3);

Though I guess that could get us in an annoying spot where we have to worry about side effects evaluating table, so I'd be fine leaving this as it is.

Copy link
Copy Markdown
Contributor Author

@GlassBricks GlassBricks Jul 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is possible to implement, however it would be inconsistent with existing lua table extension functions.
Perhaps this could be done in another PR.

@GlassBricks GlassBricks requested a review from Perryvw July 14, 2022 19:37
@Perryvw Perryvw merged commit 7ff29f0 into TypeScriptToLua:master Jul 14, 2022
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

Successfully merging this pull request may close these issues.

2 participants