ern0 ern0 - 4 months ago 18
Python Question

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

I know, It's a very trivial question, but I haven't found any example, so I am stucked now.

I have a very simple Haxe object. This is the content of the file

Thing.hx
:

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


I can compile it:

haxe Thing.hx -python Thing.py


The result is some magic, the content of
Thing.py
is:

class Thing:

pass

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


My
DoTheThing.py
Python program wants to use this:

import Thing


But it fails right on the
import
statement:

NameError: name '_hx_AnonObject' is not defined


Also, in my real project, I have a more complex Haxe class, which, when I include it from Python, occurs this error:

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


What Python modules should they include? How can I figure out, what modules should I include for my Haxe classes?

Answer

Finally, I've figured out that I need to add some haxe compiler option to include the missing methods.

First I needed to install nape:

haxelib install nape

Then compile:

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

(Source: How do I convert these Haxe source files to Python?)