Project

wasmtime

0.01
There's a lot of open issues
A Ruby binding for Wasmtime, a WebAssembly runtime.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies

Runtime

~> 0.9.39
 Project Readme

wasmtime-rb

Ruby embedding of Wasmtime

A Bytecode Alliance project

CI status

Status

The Wasmtime Ruby bindings are still under development, some features are still missing.

Installation

Install from RubyGems

gem install wasmtime

Or use in your Gemfile:

gem "wasmtime", "~> 0.3.0"

Usage

Example usage:

require "wasmtime"

# Create an engine. Generally, you only need a single engine and can
# re-use it throughout your program.
engine = Wasmtime::Engine.new

# Compile a Wasm module from either Wasm or WAT. The compiled module is
# specific to the Engine's configuration.
mod = Wasmtime::Module.new(engine, <<~WAT)
  (module
    (func $hello (import "" "hello"))
    (func (export "run") (call $hello))
  )
WAT

# Create a store. Store can keep state to be re-used in Funcs.
store = Wasmtime::Store.new(engine, {count: 0})

# Define a Wasm function from Ruby code.
func = Wasmtime::Func.new(store, Wasmtime::FuncType.new([], [])) do |caller|
  puts "Hello from Func!"
  puts "Ran #{caller[:count]} time(s)"
end

# Build the Wasm instance by providing its imports.
instance = Wasmtime::Instance.new(store, mod, [func])

# Run the `run` export.
instance.invoke("run")

# Or: get the `run` export and call it.
instance.export("run").call

For more, see examples or the API documentation.