-
Notifications
You must be signed in to change notification settings - Fork 0
Embedding Guide
Derek Snider edited this page May 19, 2026
·
1 revision
madc can be embedded in your C/C++ applications via libmadc — a shared library that exposes madc's compiler and runtime as a C++ API.
#include <libmadc/api.h>
int main() {
madc::program pgm;
pgm.exec_file("script.mad");
return 0;
}The main entry point. A pimpl wrapper over the internal Program class.
madc::program pgm;
// Compile and run a file
pgm.exec_file("script.mad");
// Compile and run a string
pgm.exec_string("puts(\"hello\");");
// Compile a file without running
pgm.compile_file("script.mad");
// Evaluate an expression
madc::value result;
pgm.eval("2 + 2", result);madc::value result;
pgm.call("my_function", {42, 3.14, "hello"}, result);call() supports up to four arguments on the scalar/C-string subset (void, bool, int64, double, const char *, std::string).
madc::value val;
pgm.get_global("my_var", val);
pgm.set_global("my_var", 42);pgm.register_function("my_callback", my_native_func, signature);Register C++ functions that scripts can call.
For simple use cases that don't need a persistent program state:
madc::exec_file("script.mad");
madc::exec_string("puts(\"hello\");");
madc::value result;
madc::eval("2 + 2", result);These create a temporary madc::program internally.
madc::program pgm;
// Lock down capabilities
pgm.set_security_policy(madc::authority_mode::system_locked);
// Set execution limits
madc::invoke_limits limits;
limits.cpu_time_ms = 5000;
limits.memory_bytes = 64 * 1024 * 1024;
pgm.set_invoke_limits(limits);system_locked mode disables process builtins, dynamic loading, and other sensitive operations.
# Install libmadc
sudo make -C src install-libmadc
# Compile your program
g++ -std=c++11 myapp.cpp -lmadc -L/usr/local/lib -I/usr/local/include -o myapp
# Run
LD_LIBRARY_PATH=/usr/local/lib ./myapp- Native Executables — compiling madc programs to standalone binaries
- CLI Reference — command-line usage
- ← Back to Home