Haxe 可以用来创建库吗?

发布于 2024-10-07 20:39:31 字数 204 浏览 0 评论 0原文

我正在考虑使用 Haxe,因为它具有跨语言能力,但不确定它是否最适合这项任务。我将编写一个通用库,该库应该能够在目标语言中使用并进行记录(能够应用 doxygen 之类的东西。)。换句话说,我想在 Haxe 中编写一个通用库,输出 c++ 代码(完成后输出 java),并让其他程序员可以访问它。(不仅仅是 C+ 编译器可读)这项任务的最佳选择,或者如果我只为每种语言编写一个版本的库会更好吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

☆獨立☆ 2024-10-14 20:39:31

当然这是可能的,尽管根据所选平台的不同可能会有些尴尬。

在 JavaScript、neko 和 Flash 上,生成的代码非常接近原生代码,人们甚至不需要知道它是在 Haxe 中生成的,就可以使用它。

关于PHP,恐怕我不太了解它是如何工作的。但是有一些命名空间黑客有点尴尬,但我认为这些可以通过用手写代码包装库来解决。

在 C++ 上,如果您不介意使用一些样板代码来启用反射,那么它基本上可以正常工作。它有一种非标准的处理构造函数的方法,而且你应该非常小心,因为它附加了一个 gc,而且我不知道它如何处理持有它不知道的引用的外部代码。

关于新目标 - C# 和 Java 将与本机代码 100% 互操作。大多数 Haxe 功能都映射到平台的本机功能(委托除外)。但如果您不在界面中公开委托,那就没问题。他们还将生成一些样板代码,以在这些平台上启用快速反射,但如果您知道自己在做什么,就会有方法禁用此功能。

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.

孤芳又自赏 2024-10-14 20:39:31

Haxe 并不是为编写跨语言库而设计的,尽管它可以完成,并且我已经看到了一些它可以工作的示例:

  • polygonal,一种可在 Haxe 和 AS3 中使用的数据结构和物理引擎。
  • verb,一个基于 NURBS 的 CAD 库,可在 Haxe 和 JS 中使用。
  • daff,一个用于比较表的库,可用于 JS、Python、Java、C#、C++、Ruby 和PHP。

然而,特别是对于 C++,由于 hxcpp 生成许多 Haxe 特定的东西,包括 GC,它可能需要大量的清理工作,或者使用起来并不简单。您可以在 Haxe 邮件列表中询问。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文