@:keep compiler metadata not working?

43 views
Skip to first unread message

JeriX

unread,
Oct 24, 2016, 10:52:21 AM10/24/16
to Haxe
hi all!

I'm trying to create instance of class not explicitly imported in Main module:
    var cl:Class<Dynamic> = Type.resolveClass('TestChildTwoClass');
   
if( cl != null )
        trace
( (Type.createInstance(cl, []):ITestInterface).getTestString() );
   
else
        trace
('class not found');
and cl is always null no matter if I mark TestChildTwoClass with @:keep or it's base class with @:keepSub
I've created simple test case project here
maybe I don't understand something about how it should work?
or maybe it is a bug?

thanks in advance
    JeriX

Simon Krajewski

unread,
Oct 24, 2016, 11:05:32 AM10/24/16
to haxe...@googlegroups.com
@:keep only has an effect if the type is actually compiled to begin with. The compiler doesn't eagerly read all your .hx files, so you have to make sure the types in question are referenced somewhere. This can be done in code or via command line: For single classes you can just specify their path (without -main), for entire packages you can use `--macro include("package.path")`.

Simon

JeriX

unread,
Oct 24, 2016, 11:50:25 AM10/24/16
to Haxe
thanks for quick response
so if don't want to explicitly mention classes I need I should place them in specific package and use --macro include("package.path")
that will help!
Reply all
Reply to author
Forward
0 new messages