Skip to content

Call a parent toString that takes an optional argument. - #1403

Open
Tutez64 wants to merge 3 commits into
HaxeFoundation:masterfrom
Tutez64:bugfix/scriptable-tostring
Open

Tutez64 wants to merge 3 commits into
HaxeFoundation:masterfrom
Tutez64:bugfix/scriptable-tostring

Conversation

@Tutez64

@Tutez64 Tutez64 commented Sep 24, 2026

Copy link
Copy Markdown

HX_DEFINE_SCRIPTABLE always calls __superString::toString() with no arguments. A Haxe toString(indent = 0) is one C++ parameter, so that call does not compile.

The zero-argument form is used when it exists. Otherwise null is passed for the default.

The cppia host build compiles OptionalToString, whose toString takes an optional argument, and ZeroArgToString, whose toString does not. Without this change that host build does not compile.

Tutez64 and others added 2 commits September 24, 2026 23:34
HX_DEFINE_SCRIPTABLE always calls __superString::toString() with no
arguments. A Haxe toString(indent = 0) is one C++ parameter, so that call
does not compile.

The zero-argument form is used when it exists. Otherwise null is passed
for the default.

Co-authored-by: Cursor <cursoragent@cursor.com>
The cppia host build is what failed: toString(indent = 0) is one C++
parameter, and the scriptable wrapper called it with none. A zero-argument
toString is compiled in the same file so that form stays valid.

Co-authored-by: Cursor <cursoragent@cursor.com>
@tobil4sk

tobil4sk commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

Seems like this is more of a specific hack to fix a program with that toString signature, but not a good general solution if the toString signature is different

A Haxe toString with parameters compiles to a C++ overload that hides
hx::Object::toString() without overriding it, whatever the parameters.
Passing null for them only worked for a single optional one. Native code
calling toString() on such an object reaches hx::Object::toString(), so
the scriptable wrapper now calls that one too.

The cppia tests now build host classes that inherit a toString with one
optional parameter and with two required ones, and check at run time
that script classes extending them print like native ones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Tutez64

Tutez64 commented Oct 3, 2026

Copy link
Copy Markdown
Author

You're right. Passing null only covered a single optional parameter. Looking closer, the failing case is a class that inherits a toString with parameters: that C++ overload hides hx::Object::toString(), and gencpp's __superString is then the class itself. Natively, Std.string on such an object reaches hx::Object::toString() whatever the signature, so in 95c73b3 the wrapper now falls back on exactly that when the parent has no zero-argument toString. The cppia tests now build host classes that inherit toString(indent = 0) and toString(indent, prefix), and check at run time that script subclasses print like native ones.

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