Create a Haxe library for zeromq

Hi,

I’m a beginner in Haxe, but not in other object languages.
I’m decided to test Haxe 4 abilities, by creating a Haxe library for zeromq framework (https://zeromq.org/).

Zeromq library is written in C, and bindings exist in all Haxe targets (ØMQ Language Bindings - zeromq). It even exists a binding for Haxe (hxzmq), but if I have well understood, it only works with C++, nekovm and PHP targets, and it is not maintained anymore.

What I would like to do is to create a Haxe library providing a common interface for zeromq in Haxe language. And for each target, a corresponding binding is used in compilation of whole application code for this target.

I will do it in Haxe 4.
How should I do it ?
Is there another Haxe library doing the same thing for another external library and for all possible targets, that I could use to inspire me ?

Well if there is an old Haxe library supporting some zeromq targets then it sounds like the best point to start. You can always add more targets.

Normally I agree, but:

  • it is 8 years old, written with an old version of Haxe, not with Haxe 4
  • it is delivered with an old version of zeromq
  • it is coded for C++

I would like to make a library independent to zeromq version, dependent to the one installed on the system. I think it will be more durable.

Haxe doesn’t have a universal way to integrate native libraries. If you are looking to do a universal integration of the native zeromq library with many Haxe targets it’ll still require to essentially integrate zeromq platform by platform.

  • Cpp / HL targets could use the modern ammer native extension library: GitHub - Aurel300/ammer: Unified FFI for Haxe native extensions - you should still take inspiration of what the old Haxe library as beyond loading the library it needs to implement a Haxe-friendly event loop,
  • Java/C#/PHP/Python/LUA/Node: these platforms require platform-specific native extensions (maybe using existing zeromq bindings). I don’t believe you can just make a universal solution, but you could discuss it in the ammer repo.

The only cross-platform way would be to implement the zeromq socket protocol only, which doesn’t use the native zeromq library but could use Haxe’s crossplatform socket implementation. This was the Flash approach (and the JS one using a Flash component), which is also outdated, but could be a good source of inspiration: Flex (ActionScript) - zeromq

1 Like

I was more thinking about something like what is done in std for Date.hx or Math.hx, with “extern” and “@:coreApi”.
I would like to create a common interface in Haxe language, so that the library can be used in any project without consideration of target language.
The difference with Date and Math, is that each target implementation will call a different binding.

For example in python, if you have installed pyzmq with pip in python, you just have to make “import zmq” to use zeromq in python code.
With Java there’s an external dependency to jeromq (managed with maven for example, or --java-lib), and you just have to make “import org.zeromq.*” to use zeromq in Java code.

API of zeromq doesn’t change a lot between versions and bindings, so I would like to make an abstraction of this API in Haxe by hiding the binding really used in target language. By this way, zeromq should be durably usable in any target language.

That’s what I meant by “implementing platform-specific wrappers”. With Python using the pip module, with Java the JAR, and for C++ I suggest to look into ammer to interop with the native library.

Still generally you can take inspiration from the old Haxe library, if you want to look at an Haxe-idiomatic API.

Thanks elsassph for your very interesting responses, I keep in mind the ammer and socket solutions.

I think first version will be only wrappers.
I am wrong to think it’s easier and faster to implement ? But more dependent on environment.

Try with something simple, like python or java yes.