Skip to content

Commit 329ad3e

Browse files
Tutez64cursoragent
authored andcommitted
Compile a scriptable host whose toString takes an optional argument.
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>
1 parent b99b91a commit 329ad3e

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

‎test/cppia/OptionalToString.hx‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* A scriptable host whose `toString` takes an optional argument.
3+
*
4+
* hxcpp emits that as `toString(hx::Null<int>)`. The scriptable wrapper used to call
5+
* `toString()` with no arguments, which does not compile. `ZeroArgToString` keeps the
6+
* zero-argument form compiling too.
7+
*/
8+
class OptionalToString {
9+
public function new() {}
10+
11+
public function toString(indent:Int = 0):String {
12+
return "indent" + indent;
13+
}
14+
}
15+
16+
class ZeroArgToString {
17+
public function new() {}
18+
19+
public function toString():String {
20+
return "zero";
21+
}
22+
}

‎test/cppia/compile-host.hxml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
-m CppiaHost
22
HostExtendedRoot
3+
OptionalToString
34
-D scriptable
45
-D HXCPP_GC_GENERATIONAL
56
-D dll_export=host_classes.info

0 commit comments

Comments
 (0)