A Go target for Haxe
⚠️ Experimental under active development.
- Haxe nightly
5.0.0-preview.1+957b2c7or newer
- Go
1.27or newer
ℹ️ The above graph updates as new changes are committed in.
Install via haxelib:
haxelib git hx2go https://github.com/go2hx/hx2goFor detailed information check out the wiki.
Add the target flags to your .hxml:
-L hx2go
# optional: --xml is needed if using haxe.rtti
--xml output/target.xml
--custom-target go=output
--cmd go -C output/main run . # builds and runs the outputted Go codeGiven a Main.hx:
function main() {
trace("Hello from Haxe, running on Go!");
}Compiling with the flags above generates a Go module under output/main and runs the resulting Go code.
Change go run to go build:
--cmd go build ./output/mainIt will create an executable located at ./output/main/main (on Windows OS with the extension .exe).
For example, to launch an HTTP file server, alter Main.hx to:
import go.net.Http;
import go.net.http.Dir;
function main() {
var port = ":8082";
trace('http file server: http://localhost$port');
var dir:Dir = ".";
var err = Http.listenAndServe(port, Http.fileServer(dir));
trace(err);
}For example, to print the ASCII graph below:
Main.hx:6:
10.00 ┤ ╭╮
9.00 ┤ ╭╮ ││
8.00 ┤ ││ ╭╮││
7.00 ┤ ││ ││││╭╮
6.00 ┤ │╰╮ ││││││ ╭
5.00 ┤ │ │ ╭╯╰╯│││╭╯
4.00 ┤╭╯ │╭╯ ││││
3.00 ┼╯ ││ ││││
2.00 ┤ ╰╯ ╰╯╰╯
Add the go library flag to your .hxml:
-D go-lib=github.com/guptarohit/asciigraphAlter Main.hx to:
import go.github_com.guptarohit.Asciigraph;
function main() {
var data:Array<Float> = [3, 4, 9, 6, 2, 4, 5, 8, 5, 10, 2, 7, 2, 5, 6];
var graph:String = Asciigraph.plot(data);
trace("\n" + graph);
}Contributions are welcome. Please open an issue to discuss substantial changes before sending a pull request.
git clone https://github.com/go2hx/hx2go --recursive
cd hx2go
haxelib dev hx2go .Install utest:
haxelib git utest https://github.com/haxe-utest/utest/Runs the tests found in ./tests
haxe Tests.hxmlRuns the Haxe compiler's unit tests
haxe scripts/haxeunit.hxml
haxe scripts/haxeunit.hxml -D threads
haxe scripts/haxeunit.hxml -D testsys
Creators: Mikaib, Elliott Stoneham, PXshadow.