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

scriptcomp: Unary stringification operator $ #55

Open
mtijanic opened this issue Jul 7, 2023 · 0 comments
Open

scriptcomp: Unary stringification operator $ #55

mtijanic opened this issue Jul 7, 2023 · 0 comments

Comments

@mtijanic
Copy link
Collaborator

mtijanic commented Jul 7, 2023

Unary operator (like ~ or !) defined for all stock types as producing a string. e.g.:

int n = 3;
string s1 = $n; // s == "3"
vector v = Vector(1.0, 2.0, 3.0);
string s2 = $v; // s == "{1.0, 2.0, 3.0}"
string s = "hello";
string s3 = $s; // s3 == "hello"

This would allow you to print a variable as string regardless of its actual input type, which allows for better code reuse, especially if coupled with a macro system of sorts.

As a stretch goal, it could support custom types too, as:

struct MyStruct { int n; };
string $_MyStruct(struct MyStruct x) { return "MyStruct: { n = " + $x.n + "}"; }

Would need VM changes, but the bulk is compiler-side

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

No branches or pull requests

1 participant