Skip to content Skip to sidebar Skip to footer

How Do I Convert These Haxe Source Files To Python?

I am trying to port the Nape physics engine (written in Haxe) to a language not supported by Haxe (Xojo). Now I don't understand Haxe but I am comfortable in Python. I'm trying to

Solution 1:

Hugh is right in that you normally need to specify a -main argument. However, you can omit that and compile a single module as well if you don't need to have an entry point (for example when compiling a library like in your case):

<dot-path> : compile the module specified by dot-path

It think doesn't really matter much which module you choose here. I went with nape.Config. The important part is using --macro include to make sure every file in the nape lib is compiled (otherwise only the ones referenced are included).

haxe nape.Config -lib nape -python nape.py--macroinclude('nape') --macroinclude('zpp_nape')

This command produces a nape.py file with around 121000 lines, which might be a bit prohibitive depending on how much work is needed to convert Python code to this Xojo language. Even if that's a simple process, generated code is typically not the most readable.

In fact, Nape's Haxe version is already not very readable, since it is generated by a preprocessor called caxe (.cx). The caxe source of Nape can be found here.


There's some compiler options you could try here to reduce the code size a bit and make it more readable:

  • --no-inline: prevents code form being inlined, reducing the output to ~60000 lines
  • -D NAPE_RELEASE_BUILD: Nape define that removes error handling - probably not worth it, only removes ~2000 more lines.

Post a Comment for "How Do I Convert These Haxe Source Files To Python?"