为了使用已编译的 Haxe 对象,我的 Python 程序应该包含什么?

What should my Python program include in order to use compiled Haxe object?

我知道,这是一个非常琐碎的问题,但我还没有找到任何例子,所以我现在被卡住了。

我有一个非常简单的 Haxe 对象。这是文件的内容 Thing.hx:

@Persistent
class Thing {
  @Property
  public var thingName: String;
}

我可以编译它:

haxe Thing.hx -python Thing.py

结果有些神奇,Thing.py的内容是:

class Thing:

  pass

  Thing.__meta__ = _hx_AnonObject({'obj': _hx_AnonObject({'Persistent': None}), 'fields': _hx_AnonObject({'thingName': _hx_AnonObject({'Property': None})})})

我的 DoTheThing.py Python 程序要使用这个:

import Thing

但它在 import 语句上失败了:

NameError: name '_hx_AnonObject' is not defined

此外,在我的实际项目中,我有一个更复杂的 Haxe class,当我从 Python 中包含它时,会出现此错误:

AttributeError: type object 'python_Boot' has no attribute 'keywords'

它们应该包含哪些 Python 模块?我怎么知道我应该为我的 Haxe classes 添加哪些模块?

最后,我发现我需要添加一些 haxe 编译器选项以包含缺少的方法。

首先我需要安装 nape:

haxelib install nape

然后编译:

haxe -lib nape Thing.hx -python Thing.py --macro "include('nape')" --macro "include('zpp_nape')"

(来源: