silverbullet icon indicating copy to clipboard operation
silverbullet copied to clipboard

Implement `syscall` hook in PlugOS

Open zefhemel opened this issue 3 years ago • 1 comments

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.

zefhemel avatar Jul 15 '22 07:07 zefhemel

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.

zefhemel avatar Sep 02 '22 14:09 zefhemel

Supported via invokeFunction("server", "plugname.functionName", arg1, arg2)

zefhemel avatar Nov 19 '22 17:11 zefhemel