Wasmtime
component/func.hh
Go to the documentation of this file.
1
2
3#ifndef WASMTIME_COMPONENT_FUNC_HH
4#define WASMTIME_COMPONENT_FUNC_HH
5
6#include <wasmtime/conf.h>
7
8#ifdef WASMTIME_FEATURE_COMPONENT_MODEL
9
10#include <string_view>
13#include <wasmtime/error.hh>
14#include <wasmtime/span.hh>
15#include <wasmtime/store.hh>
16
17namespace wasmtime {
18namespace component {
19
23class Func {
25
26public:
28 explicit Func(const wasmtime_component_func_t &func) : func(func) {}
29
31 const wasmtime_component_func_t *capi() const { return &func; }
32
36 Span<Val> results) const {
38 &func, cx.capi(), Val::to_capi(args.data()), args.size(),
39 Val::to_capi(results.data()), results.size());
40 if (error != nullptr) {
41 return Error(error);
42 }
43 return std::monostate();
44 }
45
50 wasmtime_error_t *error =
52 if (error != nullptr) {
53 return Error(error);
54 }
55 return std::monostate();
56 }
57};
58
59} // namespace component
60} // namespace wasmtime
61
62#endif // WASMTIME_FEATURE_COMPONENT_MODEL
63
64#endif // WASMTIME_COMPONENT_FUNC_H
Errors coming from Wasmtime.
Definition: error.hh:25
Fallible result type used for Wasmtime.
Definition: error.hh:82
Span class used when c++20 is not available.
Definition: span.hh:47
std::size_t size() const
Returns number of data that referred by Span class.
Definition: span.hh:81
T * data() const
Returns pointer to data.
Definition: span.hh:78
An interior pointer into a Store.
Definition: store.hh:60
const wasmtime_context_t * capi() const
Returns the underlying C API pointer.
Definition: store.hh:154
Class representing an instantiated WebAssembly component.
Definition: component/func.hh:23
const wasmtime_component_func_t * capi() const
Returns the underlying C API pointer.
Definition: component/func.hh:31
Result< std::monostate > post_return(Store::Context cx) const
Invokes the post-return canonical ABI option, if specified.
Definition: component/func.hh:49
Result< std::monostate > call(Store::Context cx, Span< const Val > args, Span< Val > results) const
Invokes this component function with the provided args and the results are placed in results.
Definition: component/func.hh:35
Func(const wasmtime_component_func_t &func)
Constructs an Func from the underlying C API struct.
Definition: component/func.hh:28
static const Raw * to_capi(const Val *capi)
Definition: component/val.hh:598
wasmtime_error_t * wasmtime_component_func_post_return(const wasmtime_component_func_t *func, wasmtime_context_t *context)
Invokes the post-return canonical ABI option, if specified, after a wasmtime_component_func_call has ...
wasmtime_error_t * wasmtime_component_func_call(const wasmtime_component_func_t *func, wasmtime_context_t *context, const wasmtime_component_val_t *args, size_t args_size, wasmtime_component_val_t *results, size_t results_size)
Invokes func with the args given and returns the result.
Build-time defines for how the C API was built.
Representation of a function in Wasmtime.
Definition: component/func.h:24
Errors generated by Wasmtime.