Skip to content

codegen

The Scriptable Meta-Programming Engine C++ And It's Community Deserve

codegen is a production-grade C++ code generation engine. You annotate structs and enums directly in source. You write a LuaU script that receives a structured AST node as JSON and emits whatever you want, C++, TypeScript, Markdown, SQL. The engine handles the rest: parsing, scheduling, deduplication, inline injection, and file routing.

It ships as a single binary. It calls nothing home. It runs the same on every machine.

Not Clang plugins

Clang plugins require a matching compiler version, link against unstable APIs, and can panic your build. codegen rules are LuaU scripts: no compiler coupling, no ABI fragility, hot-swappable at any time.

Not template engines

Jinja2 and Mustache are dumb string renderers. They cannot reason about your type system, your namespace hierarchy, or your template arguments. codegen rules receive a fully-resolved AST node: every type, every qualifier, every annotation.

Not reflection libraries

Runtime reflection adds overhead and forces you to ship introspection code. codegen generates at build time. The output is plain source. Zero runtime cost. Zero dependencies added to your library.

Not a macro system

Macros expand in-place, break debuggers, and make error messages unreadable. codegen emits separate .g.cpp files: fully navigable, fully debuggable, diffable in version control.


Deterministic output

Same source ☛ same output. Always. The engine is a pure function over your AST. Generated files are stable across machines and CI runs, making diffs meaningful and code review tractable.

Non-1:1 generation

Most generators emit one output file per input file. codegen does not require this. A grouping.luau script routes each matched entity to any output path, fan-in dozens of structs into a single api-reference.md, or fan-out one entity into multiple files. The topology is yours to define.

LLM-ready AST schema

The C++ AST is fully serialized as JSON before any rule sees it. This means your rules are testable without a compiler, inspectable with jq, and the same schema is exposed via the MCP server: making codegen a native substrate for LLM-driven code intelligence pipelines.

Isolated execution

LuaU runs in a sandboxed VM. Rules have no filesystem access, no network access, no process spawning: unless you explicitly grant permissions in the config. A malicious rule in a third-party library cannot exfiltrate your source code.

Inline injection

Rules can emit a source (to a .g.cpp file) and an inline list, declarations injected back into the original header at a designated anchor comment. This enables keeping declarations and implementations in sync without manual effort.

Self-hosted

codegen generates parts of its own infrastructure. The tool eats its own cooking, which means every feature you use has already been tested against a 100k+ LoC real-world codebase.


Annotate a C++ enum:

color.h
// [[codegen::generated::ToString::qualified::Color]]
enum class Color { Red, Green, Blue };

Write a LuaU rule (ToString.luau):

.codegen/rules/ToString/ToString.luau
return function(input)
local node = json.decode(input)
local cases = {}
for _, e in ipairs(node.enumerators or {}) do
table.insert(cases, ' case ' .. node.identifier.name .. '::' .. e.name
.. ': return "' .. e.name .. '";')
end
return json.encode({
source = "std::string_view toString(" .. node.identifier.name .. " e) {\n"
.. " switch (e) {\n"
.. table.concat(cases, "\n") .. "\n"
.. ' default: return "<unknown>";\n }\n}',
inline = { { source = "std::string_view toString(" .. node.identifier.name .. " e);" } }
})
end

Run the engine:

Terminal window
codegen --config .codegen/rules/ToString/ToString.config.yaml --input ./include

Output, written to color.g.cpp:

color.g.cpp
// generated - do not edit
#include <string_view>
std::string_view toString(Color e) {
switch (e) {
case Color::Red: return "Red";
case Color::Green: return "Green";
case Color::Blue: return "Blue";
default: return "<unknown>";
}
}

Community

Free forever

For open-source projects and personal exploration.

  • CLI-only interface
  • All built-in rule examples included
  • Community support (GitHub Issues)

No commercial use.

Professional

$7 / month · Individual

For solo developers building commercial software.

  • Everything in Community
  • TUI diff viewer: review generated changes before applying
  • VS Code DAP debugger: step through LuaU rules in the editor
  • Local persistence: rule output caching across runs

Pays for itself if it saves you 10 minutes of debugging per month.

Team

$24 / seat / month · Organization

For engineering teams that ship at scale.

  • Everything in Professional
  • CMake integration: rules run as part of the build graph
  • Shared preamble & grouping libraries: version-control your org’s conventions
  • Priority support: direct response SLA

The CMake integration alone eliminates the “forgot to regenerate” class of CI failures.