Use Haxe to develop and deliver a framework/solution in many target languages

Hello everyone,

I just discovered Haxe, and I’m really excited to learn it and use it on my current project.
I know very well C++, Python and Java, so I’m sure I will learn it very fast, but I feel I will need practice to understand all subtleties of Haxe.
Before starting, I have some questions, to be sure it suits my current needs.

I rapidly explain my needs. I am developing a high level solution, multi-platform and multi-language, splitted in many projects (with inter dependencies), and each project has dependencies to other frameworks and libraries. Some projects must be available in any language (at least most popular object oriented: python, java, C++, C#). There’s the problem of dependencies that are not multi-platform and multi-language, so I will use bindings when possible, and probably IPC with dedicated external processes. Some projects will be very specialized and thus available only in some target languages (ex: project with real time needs). In some cases I will have to specialize how actions are done in each target language, because they must be developed differently with dedicated algorithms.
Yes it’s a very big project and very complex, I’m a little bit masochistic :wink:

In fact some parts of some projects were already coded, in different languages (C++, Python, Java). I want to unify all functionalities in a global solution, by rewritting all from scratch (need core refactoring).

As there’s a lot of work in each target language, I looked for a meta-language so that most coding effort is done one time for all target languages to save a lot of time (in development, synchronization between languages after evolutions, testing each language version,…). If I have well understood, Haxe is currently the best solution for this, perhaps even the only one.

I know that, if I use Haxe, I will have to use almost all abilities of Haxe and libraries. I will probably create missing libraries, or make workarounds with external processes and IPC (like zeromq).

I looked rapidely documentation, and I still wonder if I will be blocked by some Haxe limitations. Perhaps I missed some documentation parts.
Can you explain me:

  1. How develop a project with 90% of code in Haxe and specialize 10% in each target language (I mean same functionality/interface specialized in each target language) ?
  2. Is it possible to compile and launch a Haxe project directly (without target language) ?
  3. Is 2. possible if project has a dependency (library) that is usable only in a target language (ex: C++) ?
  4. How create a binding to an installed system library written in another language (it can be a solution for 3.) ?
  5. Is it possible to call an external framework API existing only in a target language without creating a dedicated Haxe library (or a binding like in 4.) ?
  6. … it will come later :wink:

My questions are perhaps too large, it’s because my needs are large.
For question 4., consider for example an API existing in C++, that can be binded with swig in other languages like OCaml.
For question 5., consider an external API written in Python or Java, and this API would like to be called in Haxe code.
I have more precise examples if needed to clarify my questions, but I need global responses.

  1. It sounds like you are looking for conditional compilation: Conditional Compilation - Haxe - The Cross-platform Toolkit

  2. I don’t really know exactly what you mean here, but there are a few options here.

  3. No, external librarys are specific to their individual targets.

  4. Ultimately each target differs a bit for how it interacts with it’s target language. For example with java you can use the command -java-lib (Compiler Usage - Haxe - The Cross-platform Toolkit) to directly use java libraries and import them like Haxe code
    There are lots of examples for calling Haxe repo in the std folder:

    Take a look at Externs - Haxe - The Cross-platform Toolkit and it would probably be worth digging around Kha and Lime. They are both hefty projects with backends for multiple languages.
    Kha/Backends at main · Kode/Kha · GitHub
    lime/src/lime/_internal/backend at develop · haxelime/lime · GitHub

  5. I kind of answered this in 4, but again it depends on the target. It’s not as well documented as it should be, but skim through the following: Target Details - Haxe - The Cross-platform Toolkit

There’s also a lot of third party libraries that help with binding libraries or communicating between targets. This you’ll have to explore on your own as I’m not well verse in that area. I know of one though: GitHub - ncannasse/webidl: Haxe support for WebIDL

Hopefully this helps or leads you in the right direction.

In case you missed them you might wanna take a look at the following too:

Hi Gassho,

Daff library is a interesting example of a library made available for multiple targets/platforms from haxe.

Thanks for your responses.
I’m decided to test Haxe 4, by writting one or two libraries that I will need in my project.
I will make other posts on more precise topics.

1 Like

Haxe comes with its own interpreter (called “Eval”, “the macro interpreter”). You can access it via the --interp arg to the compiler. See the compiler usage chapter of the manual. See also this blog post on Eval.

Thanks John to complete other responses :wink: