Skip to content

C++ Addon

Yichao Yu edited this page Jan 20, 2021 · 1 revision

The C++ addon is used to call functions in libnacs so that we can reuse the code we wrote that's shared between multiple platforms/services.

The addon itself is located in the addon/ directory. We use cmake instead of any nodejs packages to compile the addon since we don't really care about compatibility with other packages (when other people want to use our website as a package) but we do care about consistency with other lab projects and compatibility with the system package manager. We use Nan to ease compatibility with multiple nodejs versions. The package does not link to any nodejs libraries. Instead, all the nodejs API functions that we call will be resolved when we are loaded into the nodejs process. Since the function we want to use can potentially run for a long time, we use the asynchronous interface wich can be translated to a Promise and be used with await fairly easily.

The server find the path of this library from the LABCTRL_LIB_DIR environment variable. For the test server, the cmake custom target will set the value to the binary directory where the library is compiled to (see tests/CMakeLists.txt). For the deployment server, the server will set this value based on the known relative installation path (see index.js).

Clone this wiki locally