jac-native-wasm

Compile native Jac modules to WebAssembly and run them in the browser.

Updated Jul 26, 2026
One-click install
npx skills add https://github.com/PMN123/trapdoor --skill jac-native-wasm-pmn123
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: jac-native-wasm
Source: https://github.com/PMN123/trapdoor/tree/main/.agents/skills/jac-native-wasm
Command: npx skills add https://github.com/PMN123/trapdoor --skill jac-native-wasm-pmn123

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Running compute-heavy Jac code in the browser normally requires a server round-trip; this Skill explains how to compile native Jac modules to WebAssembly and call them directly from client code at native speed. ## Core Features & Use Cases - na import edge: Import a .na.jac module from client code so the build emits /static/<stem>.wasm and binds lazy async stubs automatically. - FFI via set_na_env: Register JS implementations for extern-declared imports (raylib-style) before the first stub call, with direct access to .exports and .mem. - Raw ABI mechanics: Covers __jac_glob_init(), BigInt i64 marshalling, libc import surfaces discovered via WebAssembly.Module.imports, and standalone jac nacompile --target wasm32 builds. - Use Case: Build an in-browser game loop or simulation where a native Jac module (e.g., a physics or prime-counting kernel) runs per requestAnimationFrame with no server involved. ## Quick Start Use the jac-native-wasm skill to compile my native Jac module to WebAssembly and call it from my client page with na import.

Frequently Asked Questions about jac-native-wasm

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I run native Jac code in the browser as WebAssembly?

Keep the native code in a .na.jac module and use na import from client code; the build emits /static/<stem>.wasm and generates lazy async stubs. Each call is awaited, and the module instantiates on first call.

How do I compile a Jac module to a standalone wasm file?

Run jac nacompile primes.jac --target wasm32 -o primes.wasm to emit a valid wasm module without a server. Instantiate it in JS, call __jac_glob_init() once, then invoke exports with BigInt arguments.

Why does calling a wasm export throw 'Cannot convert to a BigInt'?

Jac int is i64 and crosses the wasm boundary as BigInt, so passing a plain JS number throws a TypeError. Pass BigInt(20000) and convert BigInt returns with Number() or f-string interpolation before arithmetic.

What imports must the JS host supply when instantiating a Jac wasm module?

Discover the exact set with WebAssembly.Module.imports(mod) rather than guessing. Modules that allocate lists, dicts, or strings import libc symbols like malloc, free, memcpy, printf, and abort, and every listed import must be present or instantiation throws.

Can Jac extern declarations like raylib work in the browser wasm target?

Yes, each extern becomes a wasm import the JS host supplies instead of linking a native library. Register the JS implementations with set_na_env before the first stub call, as demonstrated by the raylib_shooter web example.