Question

Note that I'm using Haxe 3.0.1 on Linux targeting Neko.

Consider the following code:

var classObject = Type.resolveClass("Foo");

Assuming that I have a class Foo in the same package as this code, this should give me a Class object with info about Foo in it. However, in my tests it is only working if I import Foo; first. If I do not import Foo then resolveClass returns null instead. This is strange to me.

I noticed that the Haxe API docs state:

The class must have been compiled to be accessible and if the Class is not in the same package, the full "dot path" must be given as part of the string.

But it is not clear to me what "must have been compiled to be accessible" means in this context or how it applies to my problem.

So, do I really need to import every class that I might want to resolve, or am I missing something else?

Was it helpful?

Solution

Firstly, you should give Type.resolveClass the fully qualified name of the class. I.e. pack.subpack.AClass.

Secondly, you may use --macro include("pack"). Which the include function is a method from haxe.macro.Compiler. --macro by default looks into that class for methods.

Lastly, the import my.package.* statement in haxe is lazy. It tell the compiler to resolve types in my.package, but not really import everything in my.package in the beginning.

OTHER TIPS

yes you have to ... but you can batch it with haxe.macro.ImportAll("package")

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top