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

2024-05-26 09:19:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我知道,这是一个非常琐碎的问题,但我还没有找到任何例子,所以我现在很困惑。你知道吗

我有一个非常简单的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.pyPython程序想要使用这个:

import Thing

但是它在import语句中失败了:

NameError: name '_hx_AnonObject' is not defined

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

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

它们应该包括哪些Python模块?我怎样才能知道,我的Haxe类应该包含哪些模块?你知道吗


Tags: 模块对象pyimportnone内容propertyclass
1条回答
网友
1楼 · 发布于 2024-05-26 09:19:11

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

首先我需要安装nape

haxelib install nape

然后编译:

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

(来源:How do I convert these Haxe source files to Python?

相关问题 更多 >