问题
First I am super new to Haxe, so I am asking super noob question here, and I have 2 of them.
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?
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)??
回答1:
No, the Haxe compiler only transpiles in one direction, which is:
Haxe Code ⭢ Selected Target
For the other direction, you'd need an external tool independent of the Haxe compiler. Over the years, several such tools were created (some abandoned):
- ActionScript 3 ⭢ Haxe:
- as3hx
- Java ⭢ Haxe:
- java2haxe
- JTransc
- C# ⭢ Haxe:
- CS2HX
- Phase
- PHP ⭢ Haxe:
- PhpToHaxe
- Go ⭢ Haxe:
- TARDIS Go
- TypeScript ⭢ Haxe:
- node-ts2hx
There's also some tools for generating externs, rather than compiling source-to-source:
- TypeScript ⭢ Haxe:
- ts2hx
- haxe-dtstohaxe
- dts2haxe
- Python ⭢ Haxe:
- pyextern
回答2:
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.
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. 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. 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 ). In your hxml complier code you may write.
-swf-lib my.swf
-java-lib my.jar
-net-lib my.dll
You cannot use a a swf or jar file with a c# 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.
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:
"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." - Quote https://github.com/HaxeFoundation/HaxeManual/wiki/Haxe-C%23
回答3:
What is your intention? Are you:
- Trying to your logic written in C# code in Haxe project targeting C#?
- Trying to your logic written in C# code in Haxe project targeting non-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.
For 2 you have to port the C# code to Haxe code manually, or with some tools mentioned by Gama11. Haxe itself does not support such conversion.
来源:https://stackoverflow.com/questions/43699181/can-haxe-compiler-convert-any-c-sharp-code-to-haxe