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

结论:已新增 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

@@ -0,0 +1,4 @@
{
"private": true,
"type": "module"
}

View File

@@ -0,0 +1,67 @@
import createLinuxCncIniModule from "../../ui/ini-panel/linuxcnc_ini.js";
function allocCString(mod, value) {
const bytes = mod.lengthBytesUTF8(value) + 1;
const ptr = mod._malloc(bytes);
mod.stringToUTF8(value, ptr, bytes);
return ptr;
}
function ensureParentPath(mod, path) {
const parts = path.split("/").filter(Boolean);
let current = "";
for (const part of parts.slice(0, -1)) {
current += `/${part}`;
try {
mod.FS.mkdir(current);
} catch {
// Directory already exists.
}
}
}
export async function createLinuxCncIniSdk(moduleOptions = {}) {
const mod = await createLinuxCncIniModule(moduleOptions);
return {
module: mod,
writeTextFile(path, text) {
ensureParentPath(mod, path);
mod.FS.writeFile(path, text, { encoding: "utf8" });
},
getString(path, section, tag) {
const pathPtr = allocCString(mod, path);
const sectionPtr = allocCString(mod, section);
const tagPtr = allocCString(mod, tag);
const outSize = 2048;
const outPtr = mod._malloc(outSize);
try {
const rc = mod._lcini_get_string(
pathPtr,
sectionPtr,
tagPtr,
outPtr,
outSize,
);
return rc === 0 ? mod.UTF8ToString(outPtr) : null;
} finally {
mod._free(pathPtr);
mod._free(sectionPtr);
mod._free(tagPtr);
mod._free(outPtr);
}
},
getFields(path, fields) {
return Object.fromEntries(
Object.entries(fields).map(([name, query]) => [
name,
this.getString(path, query.section, query.tag),
]),
);
},
};
}