Home Demos Forum Research Guide
Viewing topic in forum 'announcements'
back to topic list

Dana v169
Dana v169 provides bug fixes and an open source release of the code behind our native libraries, available on GitHub. We discuss the latter in some detail here.

Native libraries

So what are these? If you look at your Dana installation you'll see a folder called resources-ext. In here are a bunch of files with the extension ".dnl". In each of these files is native machine code, compiled from C code, which helps Dana to interface with your operating system in various ways.

When you open a TCP socket, or get the current system time, this results in function calls being made into one or more of these native libraries. By making them open source we're hoping that others can contribute to them - improving the ones we have and also making new libraries for functionality that's missing.

So first, a little more detail on Dana's architecture and how it uses native libraries. Dana's runtime is designed as a minimal intepreter that is as generalised and platform-separated as possible. The vast majority of the code in the virtual machine does not therefore make any OS-specific calls and does not use any hardware-specific functionality. The intention here is to maximise the portability of the interpreter itself and also to avoid "feature creep". Instead, almost all OS and hardware-specific functionality is written in an extensible set of external libraries outside the interpreter.

These libraries are designed so that, from within regular Dana code, they look like normal Dana components. When we load a native library from Dana we can therefore query it for an interface in the usual way, and we can instantiate an object from this interface:


lib = new Timer() from inl.load("timer") :< Timer
 


We can then make normal function calls on the "lib" object as if it was any other Dana object. There is then a complex chunk of glue code that sits between the Dana language and a native library to make this work - allowing a native library to appear as if it is a regular Dana component.

The Dana compiler generates this glue code for you using the -gni option, passing in a source file containing a Dana interface definition. More documentation, including a full worked example, is available with the source code at the link below.

By making this functionality open source we hope that you can write your own native libraries in cases where you find that you need to make native calls that aren't supported by the standard set of libraries that ship with Dana. If you're an awesome GUI or TCP programmer you can also contribute to the existing standard libraries by improving them, or even submitting new ones.

Full source code is on GitHub: https://github.com/projectdana/native_libraries

Happy coding :-)
by barry on 2016-06-10 06:50:28 (0 replies)

© Francis Research Ltd. 2018