This document explains the automated pipeline used to generate, refine, and embed the Lua API documentation and autocomplete data into CtrlrX.
To ensure the Lua environment stays synchronized with the C++ source code while remaining user-friendly, the API follows a three-stage build process.
The Scraper scans the C++ source files for luabind module definitions to create the "ground truth" of the API.
- Location:
python Scripts/luabind_parser.py - What it does: * Parses
.cppfiles forclass_<T>definitions and.def()method calls. - Indexes C++ headers to extract method signatures and arguments.
- Consolidation: Automatically merges "L" wrappers (e.g.,
LMemoryBlock) into their base JUCE classes (e.g.,MemoryBlock). - Pruning: Removes empty "placeholder" classes (like empty
JorJUCEtags) to keep the API clean.
The Patcher takes the raw XML and applies "Quality of Life" improvements specifically for the Lua scripting environment.
- Location:
Scripts/lua_api_patcher.py - What it does:
- Enum Flattening: Automatically flattens nested enum structures so users can type
Justification.leftinstead ofJustification.Flags.left. - Aliasing: Creates deep-copy aliases for common Lua shortcuts (e.g., mapping
CtrlrPaneltopanel). - Manual Patches: Injects constructors or special method signatures that are handled dynamically by Lua and cannot be easily scraped from C++.
To ensure the API Browser and Autocomplete work "out-of-the-box" on all platforms (especially Linux) without external file dependencies, the XML is baked into the executable.
- Source File:
Source/Resources/XML/LuaAPI.xml - Mechanism: When the project is saved in Projucer, it refreshes
BinaryData.cpp, converting the XML file into a static byte array. - Runtime: The
CtrlrLuaApiDatabaseandCtrlrLuaMethodAutoCompleteManagerload the XML directly from memory usingBinaryData::LuaAPI_xml.
Follow these steps if you have added new C++ bindings or want to update the Lua documentation:
Open a terminal in the CtrlrX root folder and run:
# Generate the raw XML from source
python3 Scripts/luabind_parser.py
# Apply Lua-specific refinements and aliases
python3 Scripts/lua_api_patcher.py
- Open
CtrlrX.jucerin the Projucer. - Press
Cmd+S(macOS) orCtrl+S(Windows/Linux) to save the project. - This step is crucial as it updates the C++ source code containing the embedded XML data.
Build the project through your IDE (Visual Studio, Xcode, etc.) or via the command line. The changes will now be visible in the Lua Method Browser and the Code Editor autocomplete.
- Missing Methods: Check if the method is correctly registered in the
luabind::moduleblock in the C++ source. - Broken Autocomplete: Ensure that
AUTO_FLATTEN_ALL_ENUMSis enabled in the patcher script if enums are appearing with incorrect paths. - Linux API Browser Empty: Ensure the build process included the
BinaryData.cppupdate and that theCtrlrLuaApiDatabaseis successfully callingloadFromMemory.