1
0
silverbullet/server/syscalls/system.ts

36 lines
976 B
TypeScript
Raw Normal View History

import { Plug } from "../../plugos/plug.ts";
import { SysCallMapping, System } from "../../plugos/system.ts";
export function systemSyscalls(
2022-11-26 13:15:38 +00:00
plugReloader: () => Promise<void>,
system: System<any>,
): SysCallMapping {
return {
"system.invokeFunction": (
ctx,
// Ignored in this context, always assuming server (this place)
_env: string,
name: string,
...args: any[]
) => {
if (!ctx.plug) {
throw Error("No plug associated with context");
}
let plug: Plug<any> | undefined = ctx.plug;
if (name.indexOf(".") !== -1) {
// plug name in the name
const [plugName, functionName] = name.split(".");
plug = system.loadedPlugs.get(plugName);
if (!plug) {
throw Error(`Plug ${plugName} not found`);
}
name = functionName;
}
return plug.invoke(name, args);
},
"system.reloadPlugs": () => {
2022-11-26 13:15:38 +00:00
return plugReloader();
},
};
}