Lynxer

Documentation

js

Run JavaScript through a Node.js subprocess.

Backend: native — stdlib/js.so, built from stdlib/js.cpp. Import: import("js") → global.js.*

Requires node on PATH; when it is missing, every runner returns "Error: node not found on PATH". A program is killed after a timeout (LYNXER_JS_TIMEOUT seconds, default 30) and answers "Error: node timed out after <n>s"; a program's stderr is captured into the result rather than inherited. A non-zero exit with no output reports "Error: node exited with status <n>". Source strings run through node -e without creating a script file. The timeout kills the command's process group, including subprocesses it started.

FunctionSignatureNotes
runJS(str code) -> strWrites the code to a temporary .js file, runs it, returns stdout
runJSFile(str path) -> strRuns a .js file and returns stdout
evalJS(str expr) -> strWraps expr in console.log(...), returns the trimmed result
nodeVersion() -> strnode --version, or ""
nodeExists() -> int1 when node runs

Example

global setup(){ import("js"); }

global main(){
    println(global.js.evalJS("1 + 2"));
    println(global.js.runJS("console.log('hello from js');"));
}

See also