Skip to content

-added support for standard array functions#234

Merged
Perryvw merged 3 commits intoTypeScriptToLua:masterfrom
andreiradu:add_array_reverse
Oct 13, 2018
Merged

-added support for standard array functions#234
Perryvw merged 3 commits intoTypeScriptToLua:masterfrom
andreiradu:add_array_reverse

Conversation

@andreiradu
Copy link
Copy Markdown
Contributor

array.shift, array.unshift, array.sort and array.reverse

sort uses table.sort which has slightly different behavior than js. It works by default with items other than string(which I think is a good thing). It's also not guaranteed to be stable.

Copy link
Copy Markdown
Member

@Perryvw Perryvw left a comment

Choose a reason for hiding this comment

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

Looks nice, would like some more tests for edge cases as indicated in the comments. We should probably also add them for the other array function tests at some point 🤔

if (params.length > 1) {
return `__TS__${func}(${params.join(", ")})`;
} else {
return `__TS__${func}(${params[0]})`;
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.

What is the purpose of this if/else? params[0] and params.join(", ") look like they would produce exactly the same result?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed this. It was intended as a fix for calling with 0 params.

// Transpile
const lua = util.transpileString(
`let testArray = ${array};
let val = testArray.shift();
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.

I would like to also have a test that checks the value of val


public transpileLuaLibFunction(func: LuaLibFeature, ...params: string[]): string {
this.importLuaLibFeature(func);
params = params.filter(element => {
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.

I still don't understand in what situation element.tostring() would be empty string, could you give an example?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sure, I hit this when calling array.unshift() with no params

@Perryvw Perryvw merged commit 1c9eca6 into TypeScriptToLua:master Oct 13, 2018
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