set: Wasm-Tabelle-Anweisung
Die table.set Tabelle-Anweisung ändert den in einem bestimmten Tabellenelement gespeicherten Wert.
Probieren Sie es aus
(module
;; Define function type
(type $ret_i32 (func (result i32)))
;; table with 0 function slots
(table $return_funcs 0 funcref)
;; Define a function of the specified type
(func $f1 (type $ret_i32)
(i32.const 42)
)
(elem declare func $f1)
(func $populate
(table.grow $return_funcs
ref.null func
(i32.const 1)
)
(drop)
(table.set $return_funcs
(i32.const 0)
(ref.func $f1)
)
)
(func (export "run") (result i32)
(call $populate)
(call_indirect (type $ret_i32) (i32.const 0))
)
)
WebAssembly.instantiateStreaming(fetch("{%wasm-url%}")).then((result) => {
const value = result.instance.exports.run();
console.log(value);
});
Syntax
table.set identifier
table.set-
Der Anweisungstyp
table.set. Muss immer zuerst angegeben werden. identifierOptional-
Ein Bezeichner für die Tabelle, in der Sie eine Referenz speichern möchten. Dies kann einer der folgenden sein:
name-
Ein bei der Erstellung der Tabelle gesetzter Name. Dieser muss mit einem
$-Symbol beginnen, zum Beispiel$my_table. index-
Die Indexnummer der Tabelle, zum Beispiel
0für die erste Tabelle im wasm-Modul,1für die zweite usw.
Wenn der
identifierweggelassen wird, wird er standardmäßig auf0gesetzt.
Typ
[index, value] -> []
Fallen
table.set löst eine Falle aus, wenn:
indexgrößer ist als