MCPcopy Create free account
hub / github.com/WebAssembly/wasm-c-api / operator<<

Function operator<<

example/callback.cc:10–34  ·  view source on GitHub ↗

Print a Wasm value

Source from the content-addressed store, hash-verified

8
9// Print a Wasm value
10auto operator<<(std::ostream& out, const wasm::Val& val) -> std::ostream& {
11 switch (val.kind()) {
12 case wasm::ValKind::I32: {
13 out << val.i32();
14 } break;
15 case wasm::ValKind::I64: {
16 out << val.i64();
17 } break;
18 case wasm::ValKind::F32: {
19 out << val.f32();
20 } break;
21 case wasm::ValKind::F64: {
22 out << val.f64();
23 } break;
24 case wasm::ValKind::EXTERNREF:
25 case wasm::ValKind::FUNCREF: {
26 if (val.ref() == nullptr) {
27 out << "null";
28 } else {
29 out << "ref(" << val.ref() << ")";
30 }
31 } break;
32 }
33 return out;
34}
35
36// A function to be called from Wasm code.
37auto print_callback(

Callers

nothing calls this directly

Calls 6

i32Method · 0.80
i64Method · 0.80
f32Method · 0.80
f64Method · 0.80
refMethod · 0.80
kindMethod · 0.45

Tested by

no test coverage detected