Files
plainleaf/client/plugos/syscalls/config.ts
T
Zef Hemel 0c9c07b3e6 Config: schema defaults, UI categories and annotations
`config.define` now propagates schema `default` values, so features like smart quotes no longer need their own fallback constants.

Adds `defineCategory` / `getCategories` for the upcoming configuration  manager UI.
2026-04-21 10:03:40 +02:00

50 lines
1.6 KiB
TypeScript

import type { SysCallMapping } from "../system.ts";
import type { Config } from "../../config.ts";
import { LuaStackFrame, luaValueToJS } from "../../space_lua/runtime.ts";
import { stripFunctions } from "../util.ts";
export function configSyscalls(config: Config): SysCallMapping {
return {
"config.get": (_ctx, path: string, defaultValue: any) => {
return config.get(path, defaultValue);
},
"config.set": (
_ctx,
keyOrValues: string | string[] | Record<string, any>,
value?: any,
) => {
config.set(keyOrValues as any, value);
},
"lua:config.setLuaValue": async (
_ctx,
keyOrValues: string | string[] | Record<string, any>,
value?: any,
) => {
// This is for special cases where we explicitly want to NOT convert a value to a JS value, but maintain its Lua version (mostly for LuaTables) — main use case: metatable
keyOrValues = await luaValueToJS(keyOrValues, LuaStackFrame.lostFrame);
config.set(keyOrValues as any, value);
},
"config.insert": (_ctx, key: string | string[], value: any) => {
config.insert(key, value);
},
"config.has": (_ctx, path: string) => {
return config.has(path);
},
"config.define": (_ctx, key: string, schema: any) => {
config.define(key, schema);
},
"config.defineCategory": (_ctx, definition: any) => {
config.defineCategory(definition);
},
"config.getValues": () => {
return stripFunctions(config.values);
},
"config.getSchemas": () => {
return stripFunctions(config.schemas);
},
"config.getCategories": () => {
return { ...config.categories };
},
};
}