Skip to content

mod_logic_c

Germán Luis Aracil Boned edited this page Apr 6, 2026 · 1 revision

mod_logic_c

Category: Logic & Scripting | Version: v1.0.0 | Source: modules/mod_logic_c/mod_logic_c.c

Description

C scripting engine. Compiles .c files with gcc at load time, produces .so, and dlopens them. Native speed with hot-reload capability. Uses portal.h directly.

Constants

#define LOGIC_C_MAX_APPS   32

Required Exports

typedef int (*app_load_fn)(portal_core_t *core);
typedef int (*app_unload_fn)(portal_core_t *core);
typedef int (*app_handle_fn)(portal_core_t *core,
                             const portal_msg_t *msg,
                             portal_resp_t *resp);

Example Application

// /var/lib/portal/apps/fast_handler/main.c
#include "portal/portal.h"

static portal_core_t *g_core = NULL;

int app_load(portal_core_t *core) {
    g_core = core;
    core->route_add(core, "/myapp/fast", "fast_handler");
    core->log(core, LOG_INFO, "fast_handler loaded");
    return 0;
}

int app_handle(portal_core_t *core,
               const portal_msg_t *msg,
               portal_resp_t *resp) {
    resp->status = 200;
    snprintf(resp->body, sizeof(resp->body), "Fast C handler: %s", msg->path);
    return 0;
}

int app_unload(portal_core_t *core) {
    core->log(core, LOG_INFO, "fast_handler unloaded");
    return 0;
}

Characteristics

  • Native speed: Compiled C, zero overhead
  • Hot-reload: Recompile + dlopen on reload
  • Direct API: Uses portal_core_t function pointers directly
  • Compile errors: Reported as load failures with gcc output

Clone this wiki locally