Macro --include is recursively including packages

2019-08-07 10:26发布

问题:

I'm building a game using the HaxeFlixel lib. In one part of my code I'm dynamically resolving classes via Type.resolveClass(). In order to avoid having to reference every potential class individually, I tried to use --macro include() by adding this to my project.xml:

<haxeflag name="--macro" value="include('my.pack')" />

This worked fine when compiling against the Flash target, but when I try to compile against neko I get:

C:\HaxeToolkit\haxe\lib\flixel/3,0,4/flixel/FlxG.hx:3: characters 7-34 : You can not access the flash package while targeting neko (for flash.display.DisplayObject)
C:\HaxeToolkit\haxe\lib\flixel/3,0,4/flixel/FlxSprite.hx:3: characters 7-18 :     referenced here
source/objects/enemies/Bat.hx:3: characters 7-23 :     referenced here
--macro:1: character 0 :     referenced here

It looks like the include macro is recursively including everything that my classes imported, including stuff that isn't appropriate for the neko target. Is there a way around this problem?

回答1:

OpenFL requires --macro allowPackage("flash") to work, which suppress the You can not access the flash package... error.

It looks like include is called before allowPackage, so you may manually call allowPackage before include:

<haxeflag name="--macro" value="allowPackage('flash')" />
<haxeflag name="--macro" value="include('my.pack')" />