Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Would Haxe work for creating libraries?

Tags:

haxe

I was thinking of using Haxe for it's cross-language ability, but wasn't sure if it was the best for this task. I'm going to write a generic library that should be able to be used in the target languages and be documented(able to apply something like doxygen.). To put it another way, I'd like to write a generic library in Haxe, output c++ code(and java once it done) , and have it accessible to other programmers.(readable to more than just the C+ compiler) Is this the best choice for this task, or would it be better if I just wrote a version of the library for each language?

like image 245
eyecreate Avatar asked Dec 16 '10 06:12

eyecreate


2 Answers

Sure it's possible, even though there might be some awkwardness depending on the chosen platform.

On JavaScript, neko and Flash, the generated code is very close to native ones, and people will be able to use it without even knowing it was generated in Haxe.

On PHP, I'm afraid I don't know very well how it works. But there is some namespace hacks that are a little awkward, but I think these could be solved by wrapping the library with hand written code.

On C++, if you don't mind with a little boilerplate code to enable reflection to work, it will work mostly alright. It has a nonstandard way of dealing with constructors, and also you should be very careful since it has a gc attached to it, and I don't know how well it handles having external code holding references it isn't aware of.

About the new targets - C# and Java will interoperate 100% with native code. Most Haxe features are mapped into the platforms' native capabilities, with the exception of delegates. But if you don't expose delegates in your interface, it's fine. They will also generate some boilerplate code as well to enable fast reflection on those platforms, but there will be ways to disable this if you know what you're doing.

like image 52
Waneck Avatar answered Oct 19 '22 03:10

Waneck


Haxe isn't designed for writing cross-language libraries, although it can be done and I've seen a few examples that it works:

  • polygonal, a data structure and physics engine usable in Haxe and AS3.
  • verb, a NURBS-based CAD Library that is usable in Haxe and JS.
  • daff, a library for comparing tables, usable in JS, Python, Java, C#, C++, Ruby, and PHP.

However, for C++ specifically, since hxcpp generates a lot of Haxe specific stuff, including GC, it may need plenty of cleanup or it is non-trivial to use. You may ask in the Haxe mailing list.

like image 43
Andy Li Avatar answered Oct 19 '22 01:10

Andy Li