Extism is a framework for executing WebAssembly plugins. The OCaml bindings require libextism, installation information is available on the Extism website
The Plugin and Manifest modules are the main modules to look at.
Type provides different types that can be encoded as input/output to Plugin.call
Function is used to define host functions and Host_function is used from inside host functions to access the plugin memory
Basic example
The following loads a Plugin from a file on disk using Manifest then calls a function with a string and prints the string output:
open Extism
let () =
let plugin =
Plugin.of_manifest_exn
@@ Manifest.create [ Manifest.Wasm.file "test/code.wasm" ]
in
let res =
Plugin.call_string_exn plugin ~name:"count_vowels" "input data"
in
print_endline res
Using the typed plugin interface you can pre-define plug-in functions:
open Extism
module Example = struct
include Plugin.Typed.Init ()
let count_vowels = exn @@ fn "count_vowels" Type.string Type.string
end
let () =
let plugin =
Example.of_plugin_exn
@@ Plugin.of_manifest_exn
@@ Manifest.create [ Manifest.Wasm.file "test/code.wasm" ]
in
let res =
Example.count_vowels plugin "input data"
in
print_endline res