Skip to content

Plugin API Hub

github-actions[bot] edited this page Dec 6, 2026 · 2 revisions

GridLock Plugin API Documentation (ABI v2.0)

GridLock provides a modular, zero-core-linkage C99 Plugin ABI v2.0 (GRIDLOCK_PLUGIN_API_VERSION = 0x00020000u, entry symbol gridlock_plugin_init) with first-class authoring support across C99, C++23, and Lua / LuaJIT.

  • C99 ABI v2.0 Reference - Complete gridlock_host_api_t vtable specification, sub-tables (core, buf, keymap, autocmd, dbg, ui, marks_regs, diag), plugin.map symbol hiding, version/size handshakes, threading guarantees, and a buildable C99 example.
  • C++23 Plugin & Host Extension Guide - extern "C" linkage, noexcept exception firewalls, std::expected / std::span / RAII wrappers, domain_mesh_probe walkthrough, and Meson/CMake build recipes.
  • Lua 5.1 / LuaJIT gl.* API Reference - Optional plugins/gridlock_lua/ scripting host (-Dlua=auto|enabled|disabled), init.lua & offline LuaRocks loading, watchdog/sandbox model, complete gl.* parameter tables (gl.dbg.eval, gl.dbg.add_breakpoint tracepoints, AnchorStore extmarks), and live GDB stack/memory + 2D heatmap examples.

1. Quick Decision Matrix: Lua / LuaJIT vs. C99 vs. C++23

Criterion Lua / LuaJIT (gl.*) Pure C99 (plugin_api.h) C++23 (extern "C")
Best For Rapid workflow automation, keymaps, autocmds, live GDB/MI HUDs, 2D canvas prototypes, init.lua workstation configs Minimal-dependency binary plugins, Rust/Zig/Fortran FFI targets, strict ABI-only scientific probes Complex HPC/solver extensions (HDF5, VTK, Eigen, PETSc/MFEM), RAII resource management, high-throughput memory parsing
Build Step None (hot-reload via lua.reload_init or Ctrl+Shift+R in Playground) cc -std=c99 -shared -fPIC Meson / CMake / Make (-std=c++23)
Core Linkage Loaded via optional libgridlock_lua.so (zero liblua in core) Zero Qt6 / zero C++ stdlib linkage Zero Qt6 linkage (noexcept C99 boundary)
Safety Guardrails 1,000,000-instruction watchdog + untrusted workspace sandbox Host boundary validation + alloc_bytes leak tracking Host boundary validation + std::expected / noexcept firewall
Distribution Single init.lua or ~/.config/gridlock/lua/ modules Prebuilt .so/.dylib/.dll or Git repo via plugins.toml Prebuilt .so/.dylib/.dll or Git repo via plugins.toml

2. Modular Header Map (include/gridlock/)

Core gridlock never links liblua and never exposes Qt6 headers across the plugin boundary. Every native plugin compiles strictly against the pure-C99 headers in include/gridlock/:

Header Sub-table / Role
include/gridlock/plugin_api.h Root gridlock_host_api_t, gridlock_plugin_descriptor_t, gridlock_plugin_init
include/gridlock/plugin_core_api.h host->core (alloc_bytes, free_bytes, log_message, paths, trust, defer_fn)
include/gridlock/plugin_buf_api.h host->buf (virtual buffers, line slices, cursor/selection, extmarks)
include/gridlock/plugin_keymap_api.h host->keymap (commands, modal/chorded keymaps, leader key, editor mode)
include/gridlock/plugin_autocmd_api.h host->autocmd (priority-ordered, glob-filtered, vetoable hooks)
include/gridlock/plugin_dbg_api.h host->dbg (rank telemetry, send_mi_async, type visualizers, badges, DWARF/memory)
include/gridlock/plugin_ui_api.h host->ui (panels, 2D retained-mode canvases, heatmaps, popups, status segments, prompts)
include/gridlock/plugin_editor_extras_api.h host->marks_regs & host->diag (marks, registers, namespaced diagnostics)

3. Plugin Lifecycle

sequenceDiagram
  participant Host as GridLock (PluginManager + PluginHostBridge)
  participant Plug as Plugin (.so / init.lua)
  participant Sub as IPluginSubsystems (buf, keymap, autocmd, dbg, ui, core)

  Host->>Plug: 1. init: gridlock_plugin_init(host, &out_desc)
  Plug-->>Host: Populate api_version (0x00020000u), metadata, plugin_ctx, shutdown
  Plug->>Sub: 2. register: commands, keymaps, autocmds, visualizers, panels/canvases
  loop Active Session
    Sub->>Plug: 3. dispatch: autocmd / keymap / command / MI reply / canvas click & key / defer_fn
    Plug->>Sub: Update panels, extmarks, diagnostics, badges, or canvas draw lists
  end
  Host->>Plug: 4. shutdown: on_session_end() -> shutdown(plugin_ctx, host)
  Host->>Sub: Sweep numericPluginId (close panels/popups, cancel timers, reclaim leaks)
  Host->>Plug: QLibrary::unload()
Loading

Every loaded plugin receives a private gridlock_host_api_t copy bound to a unique PluginBindingContext. When a plugin is disabled, hot-reloaded, or unloaded, every IPluginSubsystem automatically reclaims its panels, floating dialogs, timers, keymaps, autocmds, type visualizers, rank badges, diagnostics, marks, and tracked allocations.


4. Isolated Testing (--config-dir) & --verify-plugin CI Gate

Sandbox Profile (--config-dir & GRIDLOCK_CONFIG_DIR)

Test native plugins and init.lua scripts without touching ~/.config/gridlock:

mkdir -p /tmp/gl-sandbox/plugins
cp builddir/plugins/gridlock_lua/libgridlock_lua.so /tmp/gl-sandbox/plugins/
cp plugins/examples/mpi_workflow_lua/init.lua /tmp/gl-sandbox/init.lua

# CLI flag (highest precedence) or environment variable:
./builddir/gridlock --config-dir /tmp/gl-sandbox
GRIDLOCK_CONFIG_DIR=/tmp/gl-sandbox ./builddir/gridlock

Precedence order: --config-dir > GRIDLOCK_CONFIG_DIR > GRIDLOCK_TEST_CONFIG_DIR > ~/.config/gridlock.

Headless CI Conformance Gate (--verify-plugin)

Gate every native plugin CI workflow on gridlock --verify-plugin <path.so>. It runs headlessly inside a temporary sandbox without opening a GUI window or mutating ~/.config/gridlock/:

# Example GitHub Actions / GitLab CI verification step:
QT_QPA_PLATFORM=offscreen gridlock --verify-plugin ./build/libmy_plugin.so

--verify-plugin exits 0 ([PASS]) only when all four gates pass (exit 1 on [FAIL]):

  1. Symbol Hygiene: Resolves gridlock_plugin_init and warns on extra global STT_FUNC or STB_GNU_UNIQUE symbols that prevent clean dlclose() hot-reloading.
  2. ABI v2.0 Handshake: Validates out_desc->api_version == 0x00020000u, struct_size, and non-empty UTF-8 metadata (plugin_id_utf8, plugin_name_utf8, plugin_version_utf8).
  3. Registration Validation: Verifies commands, keymaps, visualizers, and PCRE2 regexes commit cleanly.
  4. Dry-Run Lifecycle & Zero Leaks: Runs init -> on_session_start(2) -> on_session_end() -> shutdown() and fails if outstandingAllocBytes() != 0.

5. Live Plugin Playground (-Dplugin_playground=true)

Enable the opt-in Plugin Playground for instant, zero-install Lua and C99 iteration:

meson setup builddir -Dlua=auto -Dplugin_playground=true
ninja -C builddir
./builddir/gridlock --config-dir /tmp/gl-sandbox

Open the PLAYGROUND tab in the left sidebar (FILES | SYMBOLS | STRINGS | PLAYGROUND), pick a built-in Lua/C99 starter or blank scratchpad, press Ctrl+Shift+R (Run / Reload) to compile/evaluate in isolation, Ctrl+S to save to disk, or Unload to tear down all playground panels, timers, and keymaps cleanly.

Clone this wiki locally