💎🕸 WebAssembly runtime for Ruby
It's basically the 0.5.0 version. The only noticeable change is that the Wasmer runtime has been updated to version 2.0.
This is a full rewrite of the entire project. This version is a candidate to become the 1.0 version.
We advise to take a look at:
Shortly, here are the new types the extension provides:
Store
, which holds the engine, the compiler etc.Module
, which represents a Wasm module, with validate
, new
,
name=
, name
, exports
, imports
, custom_sections
,
serialize
and deserialize
,Instance
, which represents a Wasm instance, with new
and
exports
,Exports
, which represents a collection of exported entities, with
respond_to_missing?
, method_missing
, and length
,ImportObject
, which represents a collection of imports that will
be passed to Instance
, with new
, contains_namespace
, and
register
,Function
, which represents an imported or exported function, with
new
, call
and type
,Memory
, which represents an imported or exported memory, with
new
, type
, size
, data_size
, grow
, + memory views that
extends Enumerable
,Global
, which represents an imported or exported global, with
new
, mutable?
, value
, value=
, and type
,Table
, which represents an imported or exported table, with new
(small API for the moment),Type
, FunctionType
, MemoryType
, GlobalType
and TableType
,ExportType
and ImportType
,Value
which represents a Wasm value,Wasi
module, which provides the Version
, StateBuilder
and
Environment
classes.As we said, the extension has been fully rewritten, and the code is likely to not be compatible anymore. Here are the most notable patches:
Support exported global variables (#32 by @Hywan)
instance = Wasmer::Instance.new bytes
x = instance.globals.x
assert x.mutable
assert_equal x.value, 7
x.value = 42
assert_equal x.value, 42
Support memory without an exported memory (#31 by @Hywan)
@memory
to nil
if none is exported (#33 by @Hywan)rake
and other dependencies (#36 by @Hywan)#19 Add the Memory.grow
method (@Hywan)
#15 Typed arrays implement the Enumerable
mixin (@irxground)
memory = instance.memory.uint8_view pointer
string = ""
# Now we can write this more Ruby idiomatic loop:
memory.each do |char|
break if char == 0
string += char.chr
end
#9 Implement instance.exports.respond_to?
to test whether an exported function exists (@irxground)
instance = Wasmer::Instance.new(self.bytes)
assert instance.exports.respond_to?(:foo)
#5 Improve Ruby exception raising (@irxground)
#16 Update Rutie (@edvakf)
#8 Handle exported functions that return nothing, aka void functions (@Hywan)
#4 Move all symbols inside the Wasmer
module (@irxground)
# Read from the `Wasmer` module.
instance = Wasmer::Instance.new()
greet
eaxmple (@Hywan)assert_nil
instead of assert_equal_nil
in tests (@Hywan)