X Tutup
Skip to content

LuaIterable language extension#981

Merged
Perryvw merged 10 commits intoTypeScriptToLua:masterfrom
tomblind:iterator-language-extension
Feb 20, 2021
Merged

LuaIterable language extension#981
Perryvw merged 10 commits intoTypeScriptToLua:masterfrom
tomblind:iterator-language-extension

Conversation

@tomblind
Copy link
Collaborator

@tomblind tomblind commented Feb 12, 2021

Another language extension for #963.

This one replaces @luaIterator with a new type: LuaIterable. To iterate multiple values, you can use LuaIterable<LuaMultiReturn<T>> (similar to @luaIterator+@tupleReturn).

This type can be returned by functions or properties. It can be used in for...of loops or manually by calling the returned function (and passing the appropriate state/value variables for iterators which require them).

I avoided deprecating @luaIterator for now, since it is heavily depended on by lua-types. Once we are able to update the npm package, this will be deprecated along with @tupleReturn.

@tomblind tomblind requested review from Perryvw and lolleko February 12, 2021 02:03
@tomblind tomblind changed the title LuaIterable and LuaMultiIterable language extensions LuaIterable language extension Feb 13, 2021
types: [path.resolve(__dirname, "../../../language-extensions")],
};

const testIterable = `
Copy link
Member

Choose a reason for hiding this comment

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

I get you don't want to repeat youself, but this is not very readable in my opinion. An improvement would be to move every iterable definition you use here closer to the tests that actually use them, maybe it might even be nice to group them with describes

)("invalid use of LuaIterable (%p)", (statement, code) => {
util.testFunction`
${code}
${statement}
Copy link
Member

Choose a reason for hiding this comment

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

It is so hard to understand what this test does, wouldn't it be easier to just declare a simple iterator function and call it here instead of the current 3-fold combinations, maybe splitting this up into 3 different tests for the different iterable types.

- LuaIterable type reworked for better lua compatibility
- language extensions now checked by brand instead of type alias name
- fixed LuaMultiReturn indirect forward, which also affected LuaIterable
- reorganized tests and added some for manual iterable usage
…eck both (also added test for property based iterables)
@tomblind tomblind requested a review from Perryvw February 15, 2021 16:25
@Perryvw Perryvw merged commit 1011713 into TypeScriptToLua:master Feb 20, 2021
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

X Tutup