ern0 ern0 - 6 months ago 23
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


class Thing {
public var thingName: String;

I can compile it:

haxe Thing.hx -python

The result is some magic, the content of

class Thing:


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

Python program wants to use this:

import Thing

But it fails right on the

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?


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 --macro "include('nape')" --macro "include('zpp_nape')"

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