开发者

Would Haxe work for creating libraries?

开发者 https://www.devze.com 2023-01-30 16:12 出处:网络
I was thinking of using Haxe for it\'s cross-language ability, but wasn\'t sure if it was the best for 开发者_StackOverflowthis task. I\'m going to write a generic library that should be able to be us

I was thinking of using Haxe for it's cross-language ability, but wasn't sure if it was the best for 开发者_StackOverflowthis 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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消