PeaBox Lab › PeaLang › Learn › Chapter 31 › Lesson 1

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

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

← Previous Next →