extism / proposals

Home for all EIPs (Extism Improvement Proposals), specification proposals and such for consideration
7 stars 3 forks source link

EIP: calling user defined functions from SDK host #5

Open nilslice opened 2 years ago

nilslice commented 2 years ago

Say a user uses the Go SDK and wants to "share" a Go function from their app to a plugin, making it an import to said plugin.

func logMessage(msg string) {
  log.Println("from plugin:", msg)
}

func main() {
  ext := extism.New()
  plugin := ext.LoadPlugin(...)

  // provide a handle to the function, adding some detail about 
  // what function to call, the "namespace" (module namespace 
  // to import from in wasm), the function name within wasm, and 
  // its params/returns
  plugin.AddFunc(logMessage, "AcmeAppLib", "log",  ...params) // tbd, how to declare the params/returns here

  out, err := plugin.Call(...)
  // ...
}
nilslice commented 2 years ago

Created EIP-004-providing-sdk-user-defined-functions.md.

joepio commented 1 year ago

this would be very useful indeed! I submitted a similar issue to fp_bindgen.