File tree 1 file changed +28
-1
lines changed
1 file changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -76,7 +76,8 @@ $ ruby simple.rb
76
76
77
77
## The ` Instance ` class
78
78
79
- Instantiates a WebAssembly module represented by bytes, and calls exported functions on it:
79
+ Instantiates a WebAssembly module represented by bytes, and calls
80
+ exported functions on it:
80
81
81
82
``` ruby
82
83
require " wasmer"
@@ -93,19 +94,45 @@ result = instance.exports.sum 1, 2
93
94
puts result # 3
94
95
```
95
96
97
+ ### Exported functions
98
+
96
99
All exported functions are accessible on the ` exports `
97
100
getter. Arguments of these functions are automatically casted to
98
101
WebAssembly values.
99
102
103
+ ### Exported memory
104
+
100
105
The ` memory ` getter exposes the ` Memory ` class representing the memory
101
106
of that particular instance, e.g.:
102
107
103
108
``` ruby
104
109
view = instance.memory.uint8_view
105
110
```
106
111
112
+ ` Instance.memory ` throws an exception if no memory is exported.
113
+
107
114
See below for more information.
108
115
116
+ ### Exported globals
117
+
118
+ The ` globals ` getter exposes the ` ExportedGlobal ` class represented an
119
+ exported global variable, e.g.:
120
+
121
+ ``` ruby
122
+ # Get the `x` global.
123
+ x = instance.globals.x
124
+
125
+ # Check whether the global is mutable.
126
+ assert x.mutable
127
+ assert_equal x.value, 7
128
+
129
+ # Update its value.
130
+ x.value = 42
131
+
132
+ # Tada!
133
+ assert_equal x.value, 42
134
+ ```
135
+
109
136
## The ` Memory ` class
110
137
111
138
A WebAssembly instance has its own memory, represented by the ` Memory `
You can’t perform that action at this time.
0 commit comments