Wasmtime
externref.hh
Go to the documentation of this file.
1
5#ifndef WASMTIME_EXTERNREF_HH
6#define WASMTIME_EXTERNREF_HH
7
8#include <wasmtime/_externref_class.hh>
9
10#ifdef WASMTIME_FEATURE_GC
11
12#include <wasmtime/_func_class.hh>
13
14namespace wasmtime {
15
18template <> struct detail::WasmType<std::optional<ExternRef>> {
19 static const bool valid = true;
20 static ValType valtype() { return ValType::externref(); }
21 static void store(Store::Context cx, wasmtime_val_raw_t *p,
22 std::optional<ExternRef> &&ref) {
23 if (ref) {
24 p->externref = ref->take_raw(cx);
25 } else {
26 p->externref = 0;
27 }
28 }
29 static void store(Store::Context cx, wasmtime_val_raw_t *p,
30 const std::optional<ExternRef> &ref) {
31 if (ref) {
32 p->externref = ref->borrow_raw(cx);
33 } else {
34 p->externref = 0;
35 }
36 }
37
38 static std::optional<ExternRef> load(Store::Context cx,
40 if (p->externref == 0) {
41 return std::nullopt;
42 }
44 wasmtime_externref_from_raw(cx.capi(), p->externref, &val);
45 return ExternRef(val);
46 }
47};
48
49} // namespace wasmtime
50
51#endif // WASMTIME_FEATURE_GC
52
53#endif // WASMTIME_EXTERNREF_HH
static ValType externref()
Convenience constructor for the externref value type.
Definition: types/_val_class.hh:140
WASM_API_EXTERN void wasmtime_externref_from_raw(wasmtime_context_t *context, uint32_t raw, wasmtime_externref_t *out)
Converts a raw externref value coming from wasmtime_val_raw_t into a wasmtime_externref_t.
A host-defined un-forgeable reference to pass into WebAssembly.
Definition: val.h:136
Container for possible wasm values.
Definition: val.h:290
uint32_t externref
Definition: val.h:327