mirror of
https://github.com/extism/extism.git
synced 2026-04-23 03:00:11 -04:00
Work in progress * Adds some inline docs which generates a yarddoc site * Adds linting and code formatting abilities using rufo * Adds a Makefile with common operations Co-authored-by: Steve Manuel <steve@dylib.so>
1.2 KiB
1.2 KiB
Extism
Getting Started
Example
require "extism"
require "json"
Extism.with_context do |ctx|
manifest = {
:wasm => [{ :path => "../wasm/code.wasm" }],
}
plugin = ctx.plugin(manifest)
res = JSON.parse(plugin.call("count_vowels", "this is a test"))
puts res["count"] # => 4
end
API
There are two primary classes you need to understand:
Context
The Context can be thought of as a session. You need a context to interact with the Extism runtime. The context holds your plugins and when you free the context, it frees your plugins. We recommend using the Extism.with_context method to ensure that your plugins are cleaned up. But if you need a long lived context for any reason, you can use the constructor Extism::Context.new.
Plugin
The Plugin represents an instance of your WASM program from the given manifest. The key method to know here is Extism::Plugin#call which takes a function name to invoke and some input data, and returns the results from the plugin.