hxcpp icon indicating copy to clipboard operation
hxcpp copied to clipboard

Abstract wrapping extern cannot find the extern

Open singpolyma opened this issue 1 year ago • 1 comments

Example:

@:include("rtc/rtc.hpp")
@:native("rtc::Description::Type")
extern enum abstract DescriptionType(Int) {
	 var Unspec;
	 var Offer;
	 var Answer;
	 var Pranswer;
	 var Rollback;
}

abstract SdpType(DescriptionType) to DescriptionType from DescriptionType {
	public static var OFFER = DescriptionType.Offer;
	public static var PRANSWER = DescriptionType.Pranswer;
	public static var ANSWER = DescriptionType.Answer;
	public static var ROLLBACK = DescriptionType.Rollback;
}

I get error:

error: ‘rtc’ has not been declared
  127 | HXDLIN(  68)            ROLLBACK = rtc::Description::Type::Rollback;

This seems to be because a new file is generated for this class, but the includes for the extern are not brought across. I tried also adding @:headerInclude for the abstract, but it seems that is ignored.

singpolyma avatar Mar 25 '24 17:03 singpolyma

The solution is to declare a extern class for the c++ enum, then use haxe abstract over that: https://github.com/HaxeFoundation/hxcpp/blob/8eeeee784cca9a271c023030d56e3f6db426076c/test/native/tests/TestNativeEnum.hx

kevinresol avatar Jan 27 '25 04:01 kevinresol