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. installed both Heaps and Visual Studio Code, let’s create a new Heaps application.
Differences with the Hello World tutorial
compile.hxmlneeds a different compilation target,hl, and other libraries to manage renderingindex.htmlfile -Concepts
compile.hxmlfile to tell it what to compile, how and where to compile it, and which libraries to include.main. -.├── .vscode/│ └── launch.json├── res/├── src/│ └── Main.hx└── compile.hxml
Create your project
helloHeapscompile.hxml--cp src-lib heaps-lib hlsdl-hl hello.hl-main Main
-cp srcTells haxe where to search for your code files-lib heapsTells haxe to import the heaps library-lib hlsdlTells haxe to import the hlsdl rendering library-hl hello.hlTells haxe to compile to hashlink bytecode in the project directory-main MainTells haxe that Main.hx is your entry point-lib hlsdltells Heaps to compile with SDL/OpenGL support. If you are on Windows you can use-lib hldxinstead.Open with VSCode
helloHeapsfolder with VSCode by launching VSCode and navigating the main menuFile > Open FolderCreate Hello World example
Main.hxin asrcfolder in your project directory and put the following contentclass Main extends hxd.App { override function init() { var tf = new h2d.Text(hxd.res.DefaultFont.get(), s2d); tf.text = "Hello Hashlink !"; } static function main() { new Main(); }}
s2dand set its text.Compile and run Output
To be able to compile and debug your application directly from vscode, you need to create a launch task..vscodedirectory in your project folder and create a new file calledlaunch.json. Add the following code to the file:{ "version": "0.2.0", "configurations": [ { "name": "HashLink", "request": "launch", "type": "hl", "cwd": "${workspaceFolder}", "preLaunchTask": { "type": "haxe", "args": "active configuration" } } ]}
F5, the project will compile and run.Ctrl-Shift-Band selecthaxe : active configurationhello.hlfile created in your project folder.compile.hxml:-D windowSize=1366x768
Debugging
You can put breakpoints into your Heaps application by clicking in the margin to left to the line number in your source code. You can then start again the problem and see it break at the desired position.Compile and Run natively
hello.hlfile contains bytecode that can be run with the HashLink virtual machine usinghl 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.compile.hxmlto use-hl out/main.cinstead of-hl hello.hl.outcontaining 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. for iOS, look at 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
