Implement `syscall` hook in PlugOS
In #15 it was asked if it's possible for plugs to define syscalls. Right now this is not really possible (only if you implement them via a type of RPC via the event bus), but actually this would be quite straight forward to do.
Quick example of how this could be encoded in plug YAML:
name: myplug
functions:
addNumbers:
path: ./mysyscall.ts:addNumbers
syscall:
name: addNumbers # do we really need this, or could we just do "syscall: true" and use the function's name as syscall name?
And then inmysyscall.ts:
export async function addNumbers(n1: number, n2: number): Promise<number> {
return n1 + n2;
}
And to invoke from another plug:
import { syscall } from "@plugos/plugos-syscall/syscall";
await syscall("myplug.addNumbers", 1, 2); // -> 3
In case the syscall is not implemented (e.g. because you don't have the myplug installed), this would result in the usual "Syscall not implemented" type of error you always get if you call a non-existing syscall.
Another approach to achieve the same is to simply implement a system.plugCall syscall taking e.g. (plugName, functionName, args) as arguments to invoke function calls across plug boundaries.
Supported via invokeFunction("server", "plugname.functionName", arg1, arg2)