How do I resolveClass without importing the type first?

给你一囗甜甜゛ 提交于 2019-12-11 03:21:17

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/21323768/how-do-i-resolveclass-without-importing-the-type-first

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!