Ir para o conteúdo principal
Version: latest - a1.11.0 ⚖️

Módulos

Estendendo as funcionalidades da Scripting API do nanos world

Módulos permitem que você estenda a funcionalidade da API de script do nanos world no lado do servidor. Atualmente apenas módulos C são suportados.

caution

Esteja ciente de que esta parte da API de script é atualmente um 'trabalho em progresso' e pode mudar a qualquer momento.

Creating your own C module

It is also possible to you create your own C/C++ module and call it's functions from nanos world.

caution

This is an advanced procedure so instabilities and even crashes may occur.

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

  1. Then, clone our example module in your computer to get start with it.
  2. 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:

src/example.cpp
loading...

Compiling your C module

To compile the example, follow the steps:

  1. Create a folder called build/: mkdir build.
  2. Enter the build folder: cd build.
  3. Run cmake ...
  4. Build it with cmake --build . --config Release

And now you will have the dlls/libs in build/Release folder.

Using your C module

Now copy the .dll file into your nanos world Server/Modules folder.

And in your Package, you can load and use it like:

-- Loads the module 'example'
local example = require('example')

-- Calls the module function 'test'
-- Will print 'Hello World' on console
Package.Log(example.test())