2022-10-28 14:17:40 +00:00
|
|
|
import { Plug } from "../../plugos/plug.ts";
|
|
|
|
import { SysCallMapping, System } from "../../plugos/system.ts";
|
2022-10-10 12:50:21 +00:00
|
|
|
import type { HttpServer } from "../http_server.ts";
|
|
|
|
|
2022-10-28 14:17:40 +00:00
|
|
|
export function systemSyscalls(
|
|
|
|
httpServer: HttpServer,
|
|
|
|
system: System<any>,
|
|
|
|
): SysCallMapping {
|
2022-10-10 12:50:21 +00:00
|
|
|
return {
|
|
|
|
"system.invokeFunction": (
|
|
|
|
ctx,
|
2022-10-28 14:17:40 +00:00
|
|
|
// Ignored in this context, always assuming server (this place)
|
|
|
|
_env: string,
|
2022-10-10 12:50:21 +00:00
|
|
|
name: string,
|
|
|
|
...args: any[]
|
|
|
|
) => {
|
|
|
|
if (!ctx.plug) {
|
|
|
|
throw Error("No plug associated with context");
|
|
|
|
}
|
2022-10-28 14:17:40 +00:00
|
|
|
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);
|
2022-10-10 12:50:21 +00:00
|
|
|
},
|
|
|
|
"system.reloadPlugs": () => {
|
|
|
|
return httpServer.reloadPlugs();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|