How I can arrange things in my project such that I can call my own Haxe library code from a Python script?
Thanks!
How I can arrange things in my project such that I can call my own Haxe library code from a Python script?
Thanks!
I realize that I need to first compile my Haxe code to Python, and then access the resulting Python code from Python.
Ah. Ok. I need to back up: How can set up and build my own Haxe library, compiling it to a Python library?
Does this look ok and customary for Haxe?
$ cd ~/dev/my-haxe-libs/my-lib-foo
$ tree -F
.
βββ LICENSE.txt
βββ py.hxml
βββ pylib/
β βββ my_pkg/
βββ README.md
βββ src/
βββ my_pkg/
βββ MyModule.hx
where my py.hxml file looks like:
-p src
-m my_pkg.MyModule
--python pylib/my_pkg/MyModule.py
and MyModule.hx contains:
package my_pkg;
class MyModule {
public static function foo() {
trace("hi");
}
}
but running haxe py.hxml
gives me this error:
$ haxe py.hxml
src/my_pkg/MyModule.hx:3: lines 3-7 : Invalid -main : my_pkg.MyModule does not have static function main
I donβt have a main
because this is a library, but commenting out the β-m
β line from py.hxml leaves me with the compiler apparently not happy with it.
Thanks!
Just omit the -m
, but keep the rest of the line - youβre not compiling a main class, you want to compile that module.
See also: Compiling libraries without main class - Compilation - Haxe programming language cookbook
Hello,
If you want to export your code as a library, you do not have to define main class.
You can find an example of library export here: Compiling libraries without main class - Compilation - Haxe programming language cookbook
Ooof!! Got it now. Thanks!
Funny. Although my haxe code is in package my_pkg
, the resulting Python module is not, but instead the class is named βmy_pkg_MyModule
β.
Anyhow, it works. Thanks!
On some targets like Python and JS, packages are βflattenedβ, which helps performance a bit. On JS. you can avoid this with -D js-unflatten
, doesnβt look like thereβs an equivalent for Python.
Β© 2018-2020 Haxe Foundation - Powered by Discourse