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

Safety rules

Worked examples

  1. Create one Registry and register a context object type.
  2. Bind each method callback with argument and return type strings that exactly match the schema.
  3. Load bytecode and schema bytes with Program::load.
  4. Create host objects before Context::set; keep owners in scope through Program::run.
  5. For the string catalog, add the fragment's functions declarations and call register_string(registry).
  6. 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

  1. Compile a tiny DSL chunk against the host schema.
  2. Diff the compiler's canonical signatures against Registry::signatures().
  3. Test a valid run and representative load/runtime failures.
  4. Confirm the host passes the exact schema bytes used by the compiler.
  5. Test object ownership and collection access over the complete script run.