12 — Extern¶
Mighty talks to other ABIs through extern blocks. The two ABIs
supported today are c for the C ABI and js for JavaScript when
targeting the web.
C interop¶
extern c { ... }imports C symbols. The declarations carry no body; the linker resolves them. Missing symbols at link time surface asMT8005 codegen_extern_unresolved.*U8is a raw pointer to a byte. Raw pointers are unsafe to dereference — you need anunsafeblock. See chapter 13.export c fn add(...) -> I32 = a + bexports a Mighty function through the C ABI. The expression body (= a + b) is the canonical one-line form (spec §10.1).
Try it¶
JavaScript interop¶
extern jsimports a JavaScript host function. Web-target builds wire these to the host environment through the WebAssembly Component Model.effect domrecords thatalerttouches the DOM. The effect system propagates this to callers so DOM-free contexts statically reject it (MT4001 effect_undeclared).- Throwing JS functions map to
Resultunless declared trap-only — see spec §22.3.
Try it¶
Next¶
Continue to 13 — Unsafe.