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
String, Number & Boolean classes & methods #1513
base: master
Are you sure you want to change the base?
Conversation
Just gotta write the tests for this one, I'm unsure if this is really the best way of doing this though, so please, have a look at the code :) |
export function __TS__New(this: void, target: LuaClass, ...args: any[]): any { | ||
if ("name" in target && typeof target.name === "string") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The niche usecases of these functions do not warrant this performance hit on every new object being created. The choice between the different constructors can be made int he compiler at compile time, no need to burden the runtime with this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concerning the classes, what way do you think we should go about handling those instead? As I did not personally find any way of directly translating new Boolean
to Boolean
, etc
(This comment is related to both this conversation, and the one below)
@@ -0,0 +1,17 @@ | |||
import { __TS__Boolean } from "../lualib/Boolean"; | |||
|
|||
export class Boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really see the added value of providing these as actual classes, I think it will just cause confusing bugs, especially since the equality comparisons will be broken. I think I would prefer to just translate new Boolean(x)
the same as Boolean(x)
.
import { __TS__String } from "./String"; | ||
import { String } from "./StringClass"; | ||
|
||
export function __TS__StringValueOf(this: unknown): string | undefined { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also don't see the added value of adding these valueOf functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added those to assist with the test cases, mainly for the Number class as it didn't have a way of getting the raw number, all ways of getting the number would either round it, or such.
And... it is something that is usually supported by js, so I thought, it shouldn't hurt to add it?
This PR aims to fix the following:
Boolean
prototype/methodBoolean
classString
prototype/methodString
classNumber
classThis TSTL Playground should showcase all of the issues noted above:
https://typescripttolua.github.io/play#code/MYewdgziA2CmB00QHMAUZYHcAEBlALgE4CWYaARABbHkCUtA3AFCiQwJJoElmpU31mrKHEQpUAIRDsAhmD4AGOoxbgRHcRhxTZ88gEZlQtezFot2AHIBXALYAjWIT76ATAGYjTIA