Skip to content
Ákos Kovács edited this page Jun 18, 2014 · 10 revisions

Introduction

AkLisp is able to load and unload dynamic libraries at run time, when it is compiled with dl. These libraries are written in C, with some extra black magic. Fortunately, you can create your own libraries with this magic, too.

An example in AkLisp

(load "file")  ; If file module is installed
(set! f (open "/etc/fstab" "r"))
(display (getline f))  ; Print the first line of */etc/fstab*
(newline)
(unload) ; After this, calling open, close, getline will trigger errors

The 'hello, world' module

You can find this example at the modules/hello.c from the project root.

#include <aklisp.h>
#include <stdio.h>

AKL_CFUN_DEFINE(hello, in, args)
{
    printf("Hello, world from 'hello' module!\n");
    /* Every function must return something,
      the type of 'akl_value' */
    return &NIL_VALUE;
}

static int hello_load(struct akl_state *in)
{
   AKL_ADD_CFUN(in, hello, "HELLO", "Hey hello!");
   return AKL_LOAD_OK;
}

static int hello_unload(struct akl_state *in)
{
   AKL_REMOVE_CFUN(in, hello);
   return AKL_LOAD_OK;
}

AKL_MODULE_DEFINE(hello_load, hello_unload, "hello"
    , "A simple demo module", "Akos Kovacs");

Clone this wiki locally