Skip to content
DuckDB community extension

luajit

In-process LuaJIT UDFs for DuckDB — JIT-compiled, parallel (per-thread states), trusted sandbox, GROUP BY aggregates, LIST/STRUCT/MAP bridges, embedded Fennel compiler

01 / SETUP

Install and load

Run these commands in a Haybarn SQL session. The extension is available from the community repository.

Haybarn 2.0.0 · SQL
INSTALL luajit FROM community;
LOAD luajit FROM community;

Using upstream DuckDB? Follow the maintainer’s installation instructions.

02 / QUERY

Usage example

SQL
-- Load and compile a UDF in one shot
SELECT message FROM luajit_module(
    mode := 'quick_compile',
    source := 'return function(x) return x * 2 + 1 end',
    sql_name := 'x2p1'
);
-- Use it immediately (auto-macro generated)
SELECT x2p1(5);
-- → 11

Provided by alitrack. Not yet verified on Haybarn 2.0.0.

Sample data & setup

About this extension

Write and run Lua functions directly in SQL. LuaJIT compiles them to native machine code with trace-based JIT, with parallel execution: each DuckDB worker thread owns its own lua_State (no global lock), so thread parallelism maps directly to LuaJIT parallelism.

Platforms: Linux x64/arm64, Windows (MSVC), macOS x64/arm64. WASM and mingw/rtools excluded (LuaJIT requires specific toolchains); linux_arm64 verified (v0.31, CI + arm64 runtime test).

Project overview from the community descriptor.

Documentation and resources

Project and build details
Repository
alitrack/duckdb-luajit
License
MIT
Maintainers
alitrack
Written in
C
Build source
c95b9a1985b9
Build definition
Community descriptor