Skip to content

josuigoa/hl-extension

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HashLink Extension

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 struct in 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.

Compiling HDLL file

With Docker

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 container docker run -it [container_id] /bin/sh
  • docker-compose up --build win -> Attach to the container docker run -it [container_id] powershell

Go to the makefile.* path and execute:

  • linux | mac: make -f makefile.[linux|mac]
    • move the newly created hlext.hdll to the path where libhl.so is, usualy /usr/local/lib
  • win: nmake -f makefile.win
    • rename hlext.dll to hlext.hdll and move it to the path where libhl.lib is.

With MSYS2 on Windows

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 -llibhl

Move hlext.hdll to the path where libhl.lib is.

Now from your IDE at project's root:

haxe .\build.hxml
hl .\main.hl

Commands breakdown

Linux and mac

gcc -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.h is needed
  • -lname: Use libname library
  • -fPIC: Position Independent Code

Windows

TODO

Usage

See Main.hx.

TODO

  • Try compiling with HLC.
  • Add a callback to C side and then call to Haxe from C.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published