cpp-dsl-sdk host authoring skill
Purpose
Guide the creation of a small C++ host that exposes a typed schema to lmscript and loads and runs bytecode with cpp-dsl-sdk.
When to use it
Use this when implementing a native application that should expose a controlled set of host objects, methods and functions to DSL scripts.
Install
Include dslvm.hpp from the SDK and compile as C++17. Add stdlib/string.hpp only if you want the optional string catalog. Use a compiler that emits the SDK's current bytecode version.
Commands
g++ -std=c++17 -Iinclude host.cpp -o host
lmscript --dsl-signatures schema.json
./host --dsl-signatures
./host --dsl scene.dslb
Inputs and outputs
- Input: binary bytecode and the exact JSON schema bytes used to compile it.
- Host setup: registry callbacks plus context pointers to host-owned objects.
- Output: host-defined effects and, for command-line programs, one standard JSON result line.
Safety rules
- Treat bytecode as trusted: the VM does not impose runtime limits or dynamic call checks.
- Pass exact schema bytes and bind every declared context, function and method signature.
- Keep objects and references returned by methods alive for all subsequent script calls.
- Check signature parity during development. Matching arity and return type are part of the schema contract.
- Expose collections as host object types with len() and at(i); DSL list/map value kinds do not exist.
Worked examples
- Create one Registry and register a context object type.
- Bind each method callback with argument and return type strings that exactly match the schema.
- Load bytecode and schema bytes with Program::load.
- Create host objects before Context::set; keep owners in scope through Program::run.
- For the string catalog, add the fragment's functions declarations and call register_string(registry).
- For collections, return typed object values and implement the indexed access behavior in the host.
Errors and exit codes
Catch dslvm::Error around load and run. Standard CLI conventions use exit 2 for compilation/argument errors, 3 for bytecode load or run errors, and 4 for application failures. Include the error code and source location when present.
How to verify
- Compile a tiny DSL chunk against the host schema.
- Diff the compiler's canonical signatures against Registry::signatures().
- Test a valid run and representative load/runtime failures.
- Confirm the host passes the exact schema bytes used by the compiler.
- Test object ownership and collection access over the complete script run.