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 (the interop namespace) and being called (code generation from your PeaLang definitions). This lesson is the second half. The in-script generators here live in the built-in analysis namespace — no import line needed; generate_sdk_from_source is a host/CLI API described below.

Registering a host function

let reg = analysis.register_host_function(
  "score_lead", "scoring", "score_lead", ["lead"], "number")
print reg["registered"]

The exact signature is register_host_function(name, module, function, arg_types=None, return_type="any"). It records a host callable by name, module path and function name; it does not install a PeaLang callback and it does not scan your project at startup. The return value is a record with registered set to true — check it when you build hosting glue.

Generate the exports

let py = analysis.generate_python_export("score_lead", ["lead"], "number")
let ts = analysis.generate_typescript_export("score_lead", ["lead"], "number")
let java = analysis.generate_java_export("score_lead", ["lead"], "Object")
write("exports/pea_export.py", py)

These three helpers return source text: a Python @pea_export decorator, a TypeScript peaExport decorator and a Java @PeaExport annotation, each with a usage comment for the named function. Their signature is (func_name, arg_types=None, return_type=...); arg_types is a list of type-name strings. Nothing is written to disk for you — save the text where your host project expects it.

Scaffolding whole SDKs

Runtime interop — calling out

let out = interop.call_python("json", "dumps", {"a": 1})
let result = interop.run("git", ["status", "--porcelain"])
let ok = interop.which("docker") != null

The built-in interop namespace (catalog name std.interop; import requires a quoted .pea file path) 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 utilities such as which. This is trusted-context power: no capability guard sits in front of it — run it in the host when you control the machine, not on untrusted scripts.

Guided practice

← Previous Next →