Skip to content

Console functions#443

Closed
hazzard993 wants to merge 14 commits intoTypeScriptToLua:masterfrom
hazzard993:console-functions
Closed

Console functions#443
hazzard993 wants to merge 14 commits intoTypeScriptToLua:masterfrom
hazzard993:console-functions

Conversation

@hazzard993
Copy link
Copy Markdown
Contributor

@hazzard993 hazzard993 commented Feb 22, 2019

For #439

Added some functions from console that translate to Lua. log, assert and trace.

console.log("Hello");               // print("Hello")
console.log("Hello %s", "there");   // prints "Hello there" in Lua
console.log("Hello", "There");      // print("Hello", "There")
console.assert(true);               // assert(true)
console.assert(true, "message");    // assert(true, "message")
console.assert(false, "Hello %s", "there"); // Fails with "Hello there" as a message
console.trace();                    // Prints a stack trace in Lua
console.trace("message");           // Prints a stack trace with "message" at the top in Lua
console.trace("Hello %s", "there"); // Prints a stack trace with "Hello there" at the top in Lua

@tomblind
Copy link
Copy Markdown
Collaborator

Will this work?

console.log("foo%%bar", "blah"); // Should print "foo%bar blah"

Also, any thoughts on console.warn and console.error?

@TestCase('console.assert(false, "message")', 'assert(false, "message");')
@TestCase('console.assert(false, "message %s", "info")', 'assert(false, string.format("message %s", "info"));')
@TestCase('console.assert(false, "message", "more")', 'assert(false, "message", "more");')
@Test("Console")
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.

You can split these up into different test cases: one for log, one for trace, one for assert, and put the input parameters in the TestCase (i.e. @TestCase(""), @TestCase("Hello %"))

switch (methodName) {
case "log":
if (expression.arguments.length > 0) {
if (ts.isStringLiteral(expression.arguments[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.

It's probably a good idea to refactor this to a private helper method under this function:

private isStringFormatTemplate(expression: ts.Expression): boolean {
    return ts.isStringLiteral(expression) && expression.text.includes("%");
}

hazzard993 and others added 11 commits February 26, 2019 15:48
* update README. add logo

* update readme

* update readme

* update readme

* update badges

* update badges

* update badges

* fix links on badges on readme

* fix link to travis
* tupleReturn improvements
- fixed `@tupleReturn` on arrow functions
- enabled inference of tupleReturn on arrow functions
- preventing wrap+unpack when using spread operator on tupleReturn function

* added tests for argument inference

* better name
@hazzard993
Copy link
Copy Markdown
Contributor Author

Welp, this has gone bad. I'm gunna try again

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.

4 participants