按建议,继续完成后续工作

结论:已新增 INI WASM JS SDK 封装,把 UI 和 Node smoke test 改为通过 SDK 调用 vendored LinuxCNC inifile.cc 的导出 C ABI,并同步更新兼容性、复用和漂移文档。
This commit is contained in:
2026-06-08 00:23:48 +08:00
parent 9a9fb5d4c1
commit 0d78849d80
7 changed files with 121 additions and 103 deletions

View File

@@ -3,14 +3,14 @@ import { fileURLToPath } from "node:url";
import { dirname, resolve } from "node:path";
import assert from "node:assert/strict";
import createLinuxCncIniModule from "../../../runtime/ui/ini-panel/linuxcnc_ini.js";
import { createLinuxCncIniSdk } from "../../../runtime/sdk/src/linuxcnc-ini.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const rootDir = resolve(__dirname, "../../..");
const wasmPath = resolve(rootDir, "runtime/ui/ini-panel/linuxcnc_ini.wasm");
const mod = await createLinuxCncIniModule({
const ini = await createLinuxCncIniSdk({
wasmBinary: readFileSync(wasmPath),
print() {},
printErr(message) {
@@ -18,33 +18,7 @@ const mod = await createLinuxCncIniModule({
},
});
function allocCString(value) {
const bytes = mod.lengthBytesUTF8(value) + 1;
const ptr = mod._malloc(bytes);
mod.stringToUTF8(value, ptr, bytes);
return ptr;
}
function queryIni(path, section, tag) {
const pathPtr = allocCString(path);
const sectionPtr = allocCString(section);
const tagPtr = allocCString(tag);
const outSize = 256;
const outPtr = mod._malloc(outSize);
try {
const rc = mod._lcini_get_string(pathPtr, sectionPtr, tagPtr, outPtr, outSize);
return { rc, value: rc === 0 ? mod.UTF8ToString(outPtr) : null };
} finally {
mod._free(pathPtr);
mod._free(sectionPtr);
mod._free(tagPtr);
mod._free(outPtr);
}
}
mod.FS.mkdir("/work");
mod.FS.writeFile(
ini.writeTextFile(
"/work/node-smoke.ini",
`[EMC]
MACHINE = wasm-node-smoke
@@ -57,21 +31,25 @@ COORDINATES = X Y Z A B
KINEMATICS = xyzbc-trt-kins
JOINTS = 5
`,
{ encoding: "utf8" },
);
assert.deepEqual(queryIni("/work/node-smoke.ini", "EMC", "MACHINE"), {
rc: 0,
value: "wasm-node-smoke",
assert.equal(
ini.getString("/work/node-smoke.ini", "EMC", "MACHINE"),
"wasm-node-smoke",
);
assert.equal(ini.getString("/work/node-smoke.ini", "TRAJ", "LINEAR_UNITS"), "mm");
assert.equal(
ini.getString("/work/node-smoke.ini", "KINS", "KINEMATICS"),
"xyzbc-trt-kins",
);
assert.equal(ini.getString("/work/node-smoke.ini", "TRAJ", "MISSING"), null);
assert.deepEqual(ini.getFields("/work/node-smoke.ini", {
machine: { section: "EMC", tag: "MACHINE" },
joints: { section: "KINS", tag: "JOINTS" },
}), {
machine: "wasm-node-smoke",
joints: "5",
});
assert.deepEqual(queryIni("/work/node-smoke.ini", "TRAJ", "LINEAR_UNITS"), {
rc: 0,
value: "mm",
});
assert.deepEqual(queryIni("/work/node-smoke.ini", "KINS", "KINEMATICS"), {
rc: 0,
value: "xyzbc-trt-kins",
});
assert.notEqual(queryIni("/work/node-smoke.ini", "TRAJ", "MISSING").rc, 0);
console.log("ini_wasm_node_smoke=ok");