Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Z3rio
Copy link
Contributor

@Z3rio Z3rio commented Oct 30, 2023

This PR aims to fix the following:

  • The Boolean prototype/method
  • The Boolean class
  • The String prototype/method
  • The String class
  • The Number class

This TSTL Playground should showcase all of the issues noted above:
https://typescripttolua.github.io/play#code/MYewdgziA2CmB00QHMAUZYHcAEBlALgE4CWYaARABbHkCUtA3AFCiQwJJoElmpU31mrKHEQpUAIRDsAhmD4AGOoxbgRHcRhxTZ88gEZlQtezFot2AHIBXALYAjWIT76ATAGYjTIA

@Z3rio
Copy link
Contributor Author

Z3rio commented Oct 30, 2023

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") {
Copy link
Member

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.

Copy link
Contributor Author

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 {
Copy link
Member

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 {
Copy link
Member

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.

Copy link
Contributor Author

@Z3rio Z3rio Oct 31, 2023

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?

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.

None yet

2 participants