Part V — The Modern Experience Layer · Chapter 31 · Lesson 1 of 2
Generating Python, TypeScript and Java exports
Interop in PeaLang splits into two halves: calling out (std.interop) and being called (code generation from your PeaLang definitions). This lesson is the second half.
Registering a host function
register_host_function("score_lead", fn(lead) {
return model_predict(lead)
})
Registered functions become callable from hosts through the embedding API and from other PeaLang modules through the standard registry. Registration is explicit — no reflection, no scanning, no surprises at startup.
Generate the exports
generate_python_export("score_lead", "exports/python/")
generate_typescript_export("score_lead", "exports/ts/")
generate_java_export("score_lead", "exports/java/")
Each generator emits a thin, typed wrapper around the same exported-function contract: argument conversion, error mapping, capability notes — the boilerplate nobody wants to write three times by hand.
Scaffolding whole SDKs
scaffold_go_sdk/scaffold_node_sdk— full client packages with layout, README and example.import_openapi— generate PeaLang connector code from an OpenAPI spec; the reverse of the Chapter 28 flow, for integrating third-party APIs.generate_connector_package— package a connector as a publishable artifact with its own conformance tests.
Runtime interop — calling out
import interop
let out = interop.call_python("json", "dumps", [{"a": 1}])
let result = interop.run("git", ["status", "--porcelain"])
let ok = interop.which("docker") != null
std.interop covers Python (call_python, import_python), native libraries (load_library, call_native, ctypes-based), processes (run, pipe_json), HTTP (http_get, http_post, json_rpc) and file/env utilities. This is trusted-context power: no capabilities guard it — run it in the host when you control the machine, not on untrusted scripts.
Guided practice
- Register one host function and generate all three exports; compile the Python export and call it.
- Compare
call_python("json", "dumps", ...)withjson_dump— know which one you are choosing and why. - Import a small OpenAPI spec with
import_openapiand read the generated connector.