As mentioned before, Hermes can execute functions written in C, and you can load them using the
dload
method:
dload("librequests.so", "httpget");
Lets say we want to write a method in C that gives us a float, and then we want to call this method from Hermes. Here is how we write that method:
// main.c
#include <hermes/AST.h>
#include <hermes/dynamic_list.h>
AST_T* getpi(AST_T* self, dynamic_list_T* args)
{
AST_T* float_ast = init_ast(AST_FLOAT);
float_ast->float_value = 3.14;
return float_ast;
}
Now, you can compile this code like so:
gcc -g -Wall -rdynamic -shared -fPIC -o libgetpi.so main.c
Now you can use the created
libgetpi.so
file in hermes like this:
dload("libgetpi.so", "getpi");
float PI = getpi();