-
Notifications
You must be signed in to change notification settings - Fork 341
Hello HashLink
HashLink is a virtual machine for Haxe. It can be used to build native desktop applications as well mobile platforms (Android / iOS) and consoles.
This tutorial requires you to have completed already the Installation, including the HashLink specific parts.
Please also read (https://github.com/HeapsIO/heaps/wiki/Hello-World) as we follow the same steps but with some changes.
Create a new folder helloHL
and a compile.hxml
file similar to what is done in Hello World example.
But instead of -js hello.js
, instead use -hl hello.hl
, your HXML file should then look like this:
-lib heaps
-lib hlsdl
-hl hello.hl
-main Hello
(Note: unlike JavaScript, you can debug in HL without compiling with -debug
)
The -lib hlsdl
tells Heaps to compile with SDL/OpenGL support. If you are on Windows you can use -lib hldx
instead.
Follow instructions on (https://github.com/HeapsIO/heaps/wiki/Hello-World) regarding compilation, and use the same Hello.hx
source file.
If everything works fine you should get a hello.hl
file compiled and ready to run.
Press F5 or do Debug > Start Debugging
. This should give you the choice to Debug with HashLink
. If not, make sure to install HashLink Debugger
extension.
If you click on HashLink
label, it will open you a .vscode/launch.json
. Change its content to the following:
{
"version": "0.2.0",
"configurations": [
{
"name": "HashLink",
"request": "launch",
"type": "hl",
"hxml": "compile.hxml",
"cwd": "${workspaceRoot}",
"preLaunchTask": {
"type" : "haxe",
"args" : "active configuration"
}
}
]
}
Now Run
again using F5
and it should open a native window showing Hello World
:
You can customize the default window size by adding the following to your compile.hxml
:
-D windowSize=1366x768
Interactive debugging should also be working if you setup a breakpoint as in Hello World sample:
The hello.hl
file contains bytecode that can be run with the HashLink virtual machine using hl hello.hl
. It does give quite good performances and have been proven by successful commercial games such as Northgard or Dead Cells.
However, it is also possible to compile the HashLink code using a native compiler. This allows to compile for consoles and mobile.
This is done by changing compile.hxml
to use -hl out/main.c
instead of -hl hello.hl
.
This will create a directory out
containing a lot of generated C code that needs to be built using a native compiler and linked to the same HashLink runtime that the HashLink virtual machine is using.
Compiling on mobile and console thus requires some knowledge with each platform compilers and build systems:
- for iOS, look at this thread
- for Android, look at this thread
- for Consoles (Nintendo Switch, Sony PS4, Microsoft XBoxOne), please contact us at nicolas
@
haxe.org if you are a registered developer for one or several of these