4.4 KiB
LinuxCNC WASM SDK
This SDK exposes browser/Node JavaScript wrappers for standalone WASM modules built from vendored LinuxCNC source.
Boundary
The SDK is a host-boundary layer only. It may:
- load generated Emscripten modules;
- allocate and free C strings;
- write text files into the Emscripten filesystem;
- call exported C ABI functions;
- return LinuxCNC-produced text output to JavaScript callers.
The SDK must not implement G-code interpretation, canonical motion behavior, tool semantics, parameter semantics, kinematics, or planner behavior. Those behaviors must continue to come from vendored LinuxCNC source through the C ABI.
Entrypoints
Use src/index.js for stable imports:
import {
createLinuxCncIniSdk,
createLinuxCncInterpSdk,
planSimConfigStaging,
} from "./src/index.js";
createLinuxCncIniSdk() wraps the INI parser module built from vendored
LinuxCNC inifile.cc and exposes getString() plus getBool(). Boolean
conversion is performed by vendored LinuxCNC iniFindBool().
createLinuxCncInterpSdk() wraps the interpreter-core module built from
vendored LinuxCNC RS274NGC sources and exposes:
runProgram(programText)runProgramWithIni(programText, iniPath)runFile(path)runFileWithIni(path, iniPath)runFileWithIniContinueOnError(path, iniPath)runSimConfigProgram({ iniPath, programPath, files, executionMode })runFiveAxisRemapFile(path, iniPath)runRemapFile(path, iniPath)runRemapIoMdiSequence(iniPath)restoreParameters(path)saveParameters(path, values)loadToolTable(path, options)saveToolTable(path)writeTextFile(path, text)readTextFile(path)
loadToolTable() accepts { randomToolChanger: true } to select the
LinuxCNC random-toolchanger branch before calling vendored
tooldata_load(). The SDK only forwards that runtime boundary flag.
runFiveAxisRemapFile() is a narrow host boundary for vendored LinuxCNC
sample-machine remap validation. Callers provide INI/remap/demo files in the
WASM filesystem; the C ABI runs vendored LinuxCNC REMAP, O-word, file
execution, and HAL adapter paths.
runRemapFile() is the generic remap-test equivalent for vendored LinuxCNC
tests such as tests/remap/duplicate-o-word. It reads LinuxCNC INI
SUBROUTINE_PATH and REMAP entries, then calls vendored LinuxCNC
Interp::parse_remap(), open(), read(), and execute().
runRemapIoMdiSequence() is a narrow regression boundary for the NGC-only
branch of vendored LinuxCNC tests/remap/remap-io/test-ngc.ini. The C ABI
reads LinuxCNC REMAP entries, then feeds the upstream test driver's MDI
command sequence into vendored Interp::execute(). JavaScript only copies the
vendored INI/subroutine files into the WASM filesystem and forwards the INI
path; it does not implement M62-M68, M66 input, or remap semantics.
runFileWithIni() is the plain interpreter-file equivalent for upstream tests
that need LinuxCNC INI search paths, such as
tests/interp/sub-call-from-sub. The C ABI reads LinuxCNC
SUBROUTINE_PATH and then calls vendored Interp::open(), read(), and
execute(); the SDK only copies files and forwards paths.
runSimConfigProgram() is a convenience host boundary for representative
LinuxCNC configs/sim programs. Callers provide { path, text, executable }
file entries, an INI path, and a program path. The SDK writes those text files
into the Emscripten filesystem, applies executable bits for user M-code files,
then forwards to runFileWithIni() by default or to runFiveAxisRemapFile()
when executionMode: "fiveAxisRemap" is explicitly requested.
planSimConfigStaging() is the companion file-staging planner for
representative LinuxCNC configs/sim programs. Callers provide the vendored
source manifest text, machine relative path, INI file name, and INI text. The
planner reads only INI file references and the manifest, then returns the INI,
[DISPLAY]OPEN_FILE, [EMCIO]TOOL_TABLE, [RS274NGC]PARAMETER_FILE,
[RS274NGC]SUBROUTINE_PATH, [RS274NGC]USER_M_PATH, and remap-NGC files that
should be copied into the Emscripten filesystem. It does not implement G-code,
tool, parameter, remap, or user-M semantics.
runFileWithIniContinueOnError() uses the same LinuxCNC-backed file execution
path but keeps the runner loop going after LinuxCNC reports an error, matching
upstream rs274 -n 0 regression tests such as tests/interp/oword-unwind.
It does not implement or reinterpret LinuxCNC error semantics.