简体   繁体   English

Haxe 编译器可以将任何 C# 代码转换为 Haxe 吗?

[英]Can Haxe compiler convert any C# code to Haxe?

First I am super new to Haxe, so I am asking super noob question here, and I have 2 of them.首先,我是 Haxe 的超级新手,所以我在这里问超级菜鸟问题,我有 2 个。

1) My first question is I know Haxe compiler can convert from Haxe to any other language (supported) but can it convert source code in other languages(supported) to Haxe? 1) 我的第一个问题是我知道 Haxe 编译器可以从 Haxe 转换为任何其他语言(支持),但它可以将其他语言(支持)的源代码转换为 Haxe 吗?

2) If it can do so how much is its capability like can it only convert a few files lets say in C# to Haxe or if I give a huge repo like lets say this https://github.com/dotnet/corefx or https://github.com/tensorflow/tensorflow will it convert everything in it (ya I know this is too much to ask, but anyways)?? 2)如果它可以这样做,它的功能有多少,比如它只能将几个文件转换为 C# 到 Haxe,或者如果我提供一个巨大的 repo,比如让我们说这个https://github.com/dotnet/corefxhttps ://github.com/tensorflow/tensorflow它将转换其中的所有内容(是的,我知道这要求太多了,但无论如何)??

No, the Haxe compiler only transpiles in one direction, which is:不,Haxe 编译器只向一个方向转译,即:

Haxe Code ⭢ Selected Target Haxe 代码 ⭢ 选定的目标

For the other direction, you'd need an external tool independent of the Haxe compiler.另一方面,您需要一个独立于 Haxe 编译器的外部工具。 Over the years, several such tools were created (some abandoned):多年来,创建了几个这样的工具(一些被放弃了):

There's also some tools for generating externs , rather than compiling source-to-source:还有一些用于生成externs 的工具,而不是编译源到源:

Gama11 answer is correct but -net-lib and externs should be added since they do allow you to use c#/mono code in your Haxe c#/mono project. Gama11 答案是正确的,但应该添加 -net-lib 和 externs,因为它们确实允许您在 Haxe c#/mono 项目中使用 c#/mono 代码。

Haxe can consume compiled code for all targets using externs ( compiler definitions ) for use within your Haxe project for that same target, for most targets you need to create suitable externs manually. Haxe 可以使用 externs(编译器定义)为所有目标使用编译代码,以便在您的 Haxe 项目中为同一目标使用,对于大多数目标,您需要手动创建合适的 externs。 However for some targets ( Java, C#, Flash ) Haxe can auto generate the externs required, although not always successful it can make it fairly painless to use existing libraries.然而,对于某些目标(Java、C#、Flash),Haxe 可以自动生成所需的外部文件,尽管并不总是成功,但它可以使使用现有库变得相当轻松。 I have found this very successful with flash and had varied success with Java target but it is always improving, and perhaps tried it once or twice with mono ( c# target ).我发现这在 flash 上非常成功,在 Java target 上也取得了不同的成功,但它总是在改进,也许在 mono ( c# target ) 上尝试过一两次。 In your hxml complier code you may write.在您的 hxml 编译器代码中,您可以编写。

-swf-lib my.swf
-java-lib my.jar
-net-lib my.dll

You cannot use aa swf or jar file with ac# project, nor a dll with a flash or java project, atleast not this way, although you can use a swf with openfl and nme when targetting c++ via special parsing libaries.您不能将 aa swf 或 jar 文件与 ac# 项目一起使用,也不能将 dll 与 flash 或 java 项目一起使用,至少不是这种方式,尽管在通过特殊解析库定位 c++ 时,您可以使用带有 openfl 和 nme 的 swf。

Technically for C# this will be described in the future Haxe manual more formally than I have, see link to github markdown page for full details:从技术上讲,对于 C#,这将在未来的 Haxe 手册中比我更正式地描述,有关完整详细信息,请参阅 github 降价页面的链接:

"Haxe can directly load .NET assembly files (.DLL) and convert its type definitions for use as Haxe types. To load a .NET assembly, use -net-lib library.dll compiler option. Haxe will then automatically parse types defined in that assembly file and make them available for import as Haxe types." “Haxe 可以直接加载 .NET 程序集文件 (.DLL) 并转换其类型定义以用作 Haxe 类型。要加载 .NET 程序集,请使用 -net-lib library.dll 编译器选项。然后 Haxe 将自动解析在该程序集文件并使它们可作为 Haxe 类型导入。” - Quote https://github.com/HaxeFoundation/HaxeManual/wiki/Haxe-C%23 - 引用https://github.com/HaxeFoundation/HaxeManual/wiki/Haxe-C%23

What is your intention?你的意图是什么? Are you:你是:

  1. Trying to your logic written in C# code in Haxe project targeting C#?在面向 C# 的 Haxe 项目中尝试使用 C# 代码编写的逻辑?
  2. Trying to your logic written in C# code in Haxe project targeting non-C#?尝试在面向非 C# 的 Haxe 项目中使用 C# 代码编写的逻辑?

For 1 you can use -net-lib so you can use the C# library directly in Haxe, so you don't need to convert the C# code to Haxe at all.对于 1,您可以使用-net-lib以便您可以直接在 Haxe 中使用 C# 库,因此您根本不需要将 C# 代码转换为 Haxe。

For 2 you have to port the C# code to Haxe code manually, or with some tools mentioned by Gama11.对于 2,您必须手动将 C# 代码移植到 Haxe 代码,或者使用 Gama11 提到的一些工具。 Haxe itself does not support such conversion. Haxe 本身不支持这种转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM