Embed in another program
Give your program a script language: a game with mods, a server with rules from its users, or a web page with a Tcl shell. The host program sets the limits and the capabilities, and each script runs inside them.

The picture shows the playground of this site. The interpreter is the WebAssembly build of ztcl, and it runs in the page.
From Zig
Add the package with zig fetch --save git+https://github.com/beetlebugorg/ztcl. Then make an interpreter, set its limits, and run a script:
var it: ztcl.Interp = undefined;
try it.init(gpa);
defer it.deinit();
it.compute_limit = 1_000_000;
it.mem_limit = 64 << 20;
const v = try it.eval("expr {6 * 7}");
const text = try it.str(v);
it.register(name, fn) adds a native command. it.output is the callback of puts. With no capability on, a script cannot reach the files, the network, the clock, or other programs of the host.
From C
libztcl is a shared library with the C API of Tcl 8.6. A program that you build for Tcl 8.6 builds against libztcl:
Tcl_Interp *interp = Tcl_CreateInterp();
Tcl_CreateObjCommand(interp, "sum", SumCmd, NULL, NULL);
int code = Tcl_Eval(interp, script);
printf("code %d result {%s}\n", code, Tcl_GetStringResult(interp));
Tcl_DeleteInterp(interp);
libztcl does not have each function of Tcl 8.6 yet. libztcl has the list of the differences.
From JavaScript
web/ztcl.mjs loads ztcl.wasm in a page, in a Web Worker, or in Node.js:
import { Interp } from "./web/ztcl.mjs";
const tcl = await Interp.create("zig-out/lib/ztcl.wasm", { computeLimit: 1_000_000 });
console.log(tcl.eval("string repeat ab 3").result); // ababab
tcl.close();
A script in a page can also change the page: Tcl in a web page has the dom commands.
The other way: modules in ztcl
ztcl::wasm runs a WebAssembly module from a Tcl script. With ztcl::wasm::host, a module in Rust or Go can start Linux guests of ztcl::vm, when the script grants the family vm to it. A module never gets more capabilities than its host.
What is in ztcl
The Zig API, libztcl, and the WebAssembly builds are part of ztcl. libztcl is experimental.
More
- Embed in Zig: the API, the capabilities, and threads.
- libztcl: the kit, extensions, and the differences.
- WebAssembly: the JS module, the exports, and the examples.
- ztcl::wasm::host and its Rust and Go examples.
- The source of the C example:
tests/libztcl/embed.c.