lmcode-cpp 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 lmcode-cpp.

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. The standard catalog lmcode_std_v3 (226 signatures, including the REST and CLI interfaces RestGet, RestPost, RestPut, RestDelete, RestPatch, RestHead, RestOptions, RestHandler, CliCommand and CliOption with rest_config, rest_route, rest_serve, rest_stop, rest_cli and the RestExchange methods) is included by each Registry; add callbacks only for host-specific functions and methods. Use a compiler that emits the SDK's current bytecode version.

Commands

g++ -std=c++17 -Iinclude host.cpp -o host
lmscript --lmcode-signatures schema.json
./host --lmcode-signatures
./host --lmcode 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 a REST or CLI program, let annotated rule entries implement the standard interfaces, call rest_route and rest_serve in the body, or dispatch an argument list with rest_cli; see the reference page for RestExchange.
  6. Use standard functions without host registration; bind only host-specific functions and methods.
  7. 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.

lmcode-cpp is the C++ member of a five-language SDK family with Rust, Go, C#, and Java siblings.