laskin
v5.0.0
Published
Reverse Polish notation calculator / programming language (WebAssembly)
Maintainers
Readme
Laskin
WebAssembly build of Laskin — a reverse Polish notation calculator / programming language inspired by Forth, RPL and Plorth.
Installation
npm install laskinRequires Node.js 22+ (or a modern browser with WebAssembly exception support).
Usage
import { createContext, LaskinError } from "laskin";
const ctx = await createContext();
ctx.run("1 2 +");
console.log(ctx.peek()); // "3"
const output = ctx.run('"hello" .');
console.log(output); // "hello\n"
try {
ctx.run("]");
} catch (error) {
if (error instanceof LaskinError) {
console.error(error.type, error.message, error.line, error.column);
}
}API
createContext(options?)— load the WASM module and return a contextcontext.run(source)— evaluate source; returns captured output (e.g. from.)context.clear()/depth()/peek()/pop()/stack()LaskinError— thrown on interpreter errors (type, optionalline/column)
File imports (import) are disabled in this build.
Options
await createContext({
locateFile(path) {
// Resolve laskin.wasm for bundlers / custom asset paths
return `/assets/${path}`;
},
});Building from source
Requires the Emscripten SDK.
npm run build