Just like how Lua has the ability to access C functions using FFI, HScript brings over ".ndll" loading from Codename Engine.
Compiling an NDLL is similar to compiling a base haxe project, only you are just compiling a library instead. To get an explanation on how to compile a project into an ndll file, refer to Codename Crew's ndll example repository.
If you wanna rename the ndll output lib, go into "project/Build.xml" and change "ndllexample"` in the "NDLL_NAME" attribute.
Here is a brief explanation on everything in the repository:
These are for Android ndlls only and can be ignored if you are making a desktop ndll.
Of course, you are not just limited to these files. Your ndll project can contain as many code files as you need, these are just the starting files for simple stuff.
There are also defines that you can use to make your ndll compatible with multiple platforms, here are the defines:
Once you're ready to compile your project into an ndll, you just open up a command prompt/terminal and run the command "lime . rebuild [system name]".
Here is a list of the available commands:
append "-32" to compile the ndll for 32bit systems and append "-debug" if you wanna compile a debug ndll.
Your compiled ndll will be in "ndll/[Platform name]64/ndllexample-[Platform name].ndll" or "ndll/[Platform name]/ndllexample-[Platform name].ndll" if it's 32 bits.
Once you have your ndll with your C++ functions, it's now usable in T-Bar Engine. For haxe scripts, you need to import the `backend.util.NdllUtil` class.
Note: On versions under 2.0, you will need to import`backend.NdllUtil` instead. You can also use conditionals to make your script compatible with multiple versions.
Some things to note:
Note: The limit for the number of arguments an external function can have is 25.
You can now use the variable as if it was any other function!
Another good tip is to refrain from using the "NdllUtil.getFunction" everytime you want to load the function, as getFunction is a bit memory expensive. It is recommended to load a variable with the function once and use that variable as a function.