C Module
C Module is a Package type that allows extending the functionalities of nanos world Scripting API
C Modules allows you to extend the functionality of the nanos world scripting API on the server side. Currently only C modules are supported.
Be aware that this part of the scripting API is currently work in progress and may change at any time.
This is an advanced procedure so instabilities and even crashes may occur.
Creating your C Module binariesβ
To create your own module, fist make sure you have Visual Studio installed with Desktop development with C++ (and CMake) or any other C compiler on Linux.
First Stepsβ
- Then, clone our example module in your computer to get start with it.
- After cloning, you will need to download it's submodules with
git submodule update --init --recursive
- this will download the module-sdk as a git submodule into deps/ folder automatically.
Understanding the exampleβ
The important file is under src/example.cpp
:
loading...
Compiling your C Moduleβ
To compile the example, follow the steps:
- Create a folder called
build/
:mkdir build
. - Enter the build folder:
cd build
. - Run
cmake ..
. - Build it with
cmake --build . --config Release
And now you will have the dlls/libs in build/Release
folder.
Creating a C Module Packageβ
First of all, create a new Package of type c-module, and add your .dll and .so files into the Package's root folder. It will look like that:
Packages/
βββ my-module/
βββ Package.toml
βββ example.dll
βββ ...
Then make sure to add example
(or the name of your dll file) to the Package.toml configuration section:
# c module configurations
[c_module]
# list of binaries paths to load (without extension)
binaries = [
"example",
]
Loading and Using your C Moduleβ
Now you can load the package you created as usual, by adding it to the Config.toml's list of Packages requirement or by adding it to another Package's Package.toml as dependency as well.
And in your Package, you can load and use it like:
-- Calls the module function 'test'
-- Will print 'Hello World' on console
Console.Log(example.test())