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>
14#include <wasmtime/error.hh>
15#include <wasmtime/span.hh>
16#include <wasmtime/store.hh>
17
18namespace wasmtime {
19namespace component {
20
24class Func {
26
27public:
29 explicit Func(const wasmtime_component_func_t &func) : func(func) {}
30
32 const wasmtime_component_func_t *capi() const { return &func; }
33
37 Span<Val> results) const {
39 &func, cx.capi(), Val::to_capi(args.data()), args.size(),
40 Val::to_capi(results.data()), results.size());
41 if (error != nullptr) {
42 return Error(error);
43 }
44 return std::monostate();
45 }
46
51 wasmtime_error_t *error =
53 if (error != nullptr) {
54 return Error(error);
55 }
56 return std::monostate();
57 }
58
61 return FuncType(wasmtime_component_func_type(&func, cx.capi()));
62 }
63};
64
65} // namespace component
66} // namespace wasmtime
67
68#endif // WASMTIME_FEATURE_COMPONENT_MODEL
69
70#endif // WASMTIME_COMPONENT_FUNC_H
Errors coming from Wasmtime.
Definition: error.hh:26
Fallible result type used for Wasmtime.
Definition: error.hh:70
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:66
const wasmtime_context_t * capi() const
Returns the underlying C API pointer.
Definition: store.hh:160
Type information about a component function.
Definition: component/types/func.hh:21
Class representing an instantiated WebAssembly component.
Definition: component/func.hh:24
FuncType type(Store::Context cx) const
Returns the type of this function.
Definition: component/func.hh:60
const wasmtime_component_func_t * capi() const
Returns the underlying C API pointer.
Definition: component/func.hh:32
Result< std::monostate > post_return(Store::Context cx) const
Invokes the post-return canonical ABI option, if specified.
Definition: component/func.hh:50
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:36
Func(const wasmtime_component_func_t &func)
Constructs an Func from the underlying C API struct.
Definition: component/func.hh:29
static const Raw * to_capi(const Val *capi)
Definition: component/val.hh:476
WASM_API_EXTERN wasmtime_component_func_type_t * wasmtime_component_func_type(const wasmtime_component_func_t *func, wasmtime_context_t *context)
Returns the type of this function.
WASM_API_EXTERN 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 ...
WASM_API_EXTERN 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:25
Errors generated by Wasmtime.