C++ Extension API
Reference documentation for creating native C++ extensions for Quartz.
Entry Point
Every extension must export an init_extension function:
extern "C" __attribute__((visibility("default")))
void init_extension(FunctionRegistry& reg) {
// Register your functions here
}
Value Type
Quartz values are represented as std::variant:
using Value = std::variant<
int, // Integer
double, // Floating point
std::string, // String
bool // Boolean
>;
Registering Functions
auto my_func = [](const std::vector<Value>& args) -> Value {
// Implementation
return Value();
};
reg.registerFunction("my.namespace.func", my_func);
Extracting Values
// Check type and extract
if (std::holds_alternative<int>(args[0])) {
int val = std::get<int>(args[0]);
}
// Extract double (handles int conversion)
double getDouble(const Value& v) {
if (std::holds_alternative<double>(v))
return std::get<double>(v);
if (std::holds_alternative<int>(v))
return static_cast<double>(std::get<int>(v));
return 0.0;
}
Build Setup
# CMakeLists.txt
add_library(my_extension SHARED my_extension.cpp)
target_include_directories(my_extension PRIVATE ../../include/core)
target_link_libraries(my_extension PRIVATE qz-core)
See the Extension Guide for complete examples.