Skip to content

Commit

Permalink
doc(readme) Explain the Instance.globals API.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Mar 3, 2020
1 parent 3a1b026 commit 6ed61e5
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ $ ruby simple.rb

## The `Instance` class

Instantiates a WebAssembly module represented by bytes, and calls exported functions on it:
Instantiates a WebAssembly module represented by bytes, and calls
exported functions on it:

```ruby
require "wasmer"
Expand All @@ -93,19 +94,45 @@ result = instance.exports.sum 1, 2
puts result # 3
```

### Exported functions

All exported functions are accessible on the `exports`
getter. Arguments of these functions are automatically casted to
WebAssembly values.

### Exported memory

The `memory` getter exposes the `Memory` class representing the memory
of that particular instance, e.g.:

```ruby
view = instance.memory.uint8_view
```

`Instance.memory` throws an exception if no memory is exported.

See below for more information.

### Exported globals

The `globals` getter exposes the `ExportedGlobal` class represented an
exported global variable, e.g.:

```ruby
# Get the `x` global.
x = instance.globals.x

# Check whether the global is mutable.
assert x.mutable
assert_equal x.value, 7

# Update its value.
x.value = 42

# Tada!
assert_equal x.value, 42
```

## The `Memory` class

A WebAssembly instance has its own memory, represented by the `Memory`
Expand Down

0 comments on commit 6ed61e5

Please sign in to comment.