HaxeFoundation / HaxeFoundation/haxe
@:nativeGen half working on cpp
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
Hello!
I didn't know that nativeGen available for cpp target, but Hugh pointed me to it.
Also, Hugh told that he implemented it only for interfaces, but unfortunately it is not working in most cases :)
Here is small example:
```haxe
package;
class App {
public static function main():Void {
var s:Something = new Something();
s.test();
//if comment this two lines, then "hello hxcpp" will be printed.
//if uncomment then nothing be printed at all.
test1(s); //not working
test2(s); //not working
}
private static function test1(s:Something):Void {
s.test();
}
private static function test2(s:ISomething):Void {
s.test();
}
}
class Something implements ISomething {
public function new() {
}
public function test():Void {
cpp.Lib.println("hello hxcpp!");
}
}
@:nativeGen
interface ISomething {
public function test():Void;
}
```
Also got compilation errors if @:nativeGen is applied on classes (but looks like it is expected, currently).
But applying it on classes and interfaces generates very clean cpp code, which is so useful in some cases.
So I'm very excited about this feature and I hope it can be fixed and implemented in the same way as for Java and C# targets.
Just look at this beautiful code (on left side with @:nativeGen, on right without) :)

Contributor guide
Assessment
This issue has not been assessed yet.