This library is created to learn how the bridge between Haxe and C works. It only has few functions:
- HLExt.new(name:String, birthYear:Int, currentYear:Int): Creates an
structin C side with given arguments, returns that struct and we save it in the Haxe side.
struct _result {
vbyte *greeting;
int age;
};- HLExt.getGreeting(): Get the name from C struct.
- HLExt.getAge(): Get the age from C struct.
- static HLExt.getHaxeObject(name:String, birthYear:Int, currentYear:Int): returns a Haxe object instead of a pointer to C side.
There are two Docker images (Windows and Linux) with the tools required for the compilation. Run the docker container for the desired OS and attach to it;
docker-compose up --build linux-> Attach to the containerdocker run -it [container_id] /bin/shdocker-compose up --build win-> Attach to the containerdocker run -it [container_id] powershell
Go to the makefile.* path and execute:
- linux | mac:
make -f makefile.[linux|mac]- move the newly created
hlext.hdllto the path wherelibhl.sois, usualy/usr/local/lib
- move the newly created
- win:
nmake -f makefile.win- rename
hlext.dlltohlext.hdlland move it to the path wherelibhl.libis.
- rename
With MSYS2 UCRT64 on Windows and with Hashlink installed in /c/HaxeToolkit/hl-1.11.0-win, from project's root:
cd hlextLib
gcc -O2 -shared -o hlext.hdll -std=c11 hlext.c -I/c/HaxeToolkit/hl-1.11.0-win/include -L /c/HaxeToolkit/hl-1.11.0-win/ -lhl -llibhlMove hlext.hdll to the path where libhl.lib is.
Now from your IDE at project's root:
haxe .\build.hxml
hl .\main.hlgcc -O3 -shared -o hlext.hdll -std=c11 hlext.c -I/usr/local/include -lhl- gcc: compiler call
- -O3: level 3 optimization
- -shared: flag to tell this is a shared library
- -o file.out: define the output file
- -std=standard: C language standard
- hlextLib/hlext.c: C file to compile
- -Idirectory: Include the directory where headers files are. In this case only
hl.his needed - -lname: Use
libnamelibrary - -fPIC: Position Independent Code
TODO
See Main.hx.
- Try compiling with HLC.
- Add a callback to C side and then call to Haxe from C.