go2hx
warning: experimental version.
Use Go libs with ease!
Standard Library compatibility/api docs
Library compilation and test results
FAQ
Can library X be compiled?
Maybe, to see if the library is supported at the moment go get library_here
the library and then run:
go list -f '{{ .Imports }}' library here
Then check to see if the standard libraries used are all passing with the compatibility table above.
Does the compiler support Go as a Haxe target?
No and it's not within the scope of the project.
Why not use externs instead of compiling Go code into Haxe?
Because externs can target lock a code base and they require maintenance, abstraction code etc.
Cgo support?
Not available but planned and happily accepting contributions for it!
How does this compare to Gopherjs or Go wasm?
go2hx's design is built with Haxe devs in mind, therefore the goals align with Haxe dev advantages of the compiler, with that said go2hx does have some advantages already, smaller code generation, access to Haxe's compiler tooling such as dce and optimizations, and Haxe as a language being very portable, high level and statically typed.
What internals does stdlib use?
go2hx's compiler, compiles the standard library packages for example os
. After compilation a Patcher system switches out functions/variables/structs for a Haxe equivalent, for example os.Open
uses sys.io.File.read
and sys.io.File.write
.
Contributing:
The project is still at an experimental level, so expect undocumented problems to spring up. The best way to contribute is to simply use the compiler on code you would like and inevitably run into errors. From there we can answer some questions to see:
how to proceed!
What time is the error happening?:
- go compiler time (
./export.go
named: go4hx) - Haxe compiler time (
src/Typer.hx
and./stdgo/internal/reflect/Reflect.hx
etc) - compile time (Haxe build tools example:
haxe build.hxml
) - runtime (Code running example:
hl build.hl
ornode build.js
).
How can the code causing the error be reduced to a simple sample?
- Use
./rnd/main.go
as a testbed and run it with:haxe rnd.hxml
- Modify the go code with debug prints or the Haxe compiled code with traces and figure out where is the precise error point.
- Copy over structs and interfaces if needed that are used by the erroring code sample.
- Make usage of go2hx's reflection for example:
println(reflect.TypeOf(value).String())
Does the code throw "not implemented" error?
- Look at the unimplemented function's documentation
- Implement the missing functionality into the Patcher
./src/Patch.hx
following the naming conventionpath:FunctionName
orpath.Type:FunctionName
for recv functions.
Is the type casting invalid?
- Look into
./src/Typer.hx
and search forfunction checkType
for implicit type conversions and for castsfunction castTranslate
- A lot of helper type functions are called in
./stdgo/internal/reflect/Reflect
for examplegetUnderlying
and the entire module is imported intoTyper.hx
so you won't see clear reference that the code is there.