-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathcomponent_instance_feat_component_model.go
More file actions
51 lines (46 loc) · 1.63 KB
/
component_instance_feat_component_model.go
File metadata and controls
51 lines (46 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package wasmtime
// #include <wasmtime.h>
import "C"
import "runtime"
// ComponentInstance is a value-type handle to an instantiated component
// living inside a [Store]. It is created by
// [ComponentLinker.Instantiate].
//
// Instances do not have a destructor; their lifetime is tied to the store
// that owns them. Passing a [ComponentInstance] to a different store is
// undefined behavior and will likely abort the process.
type ComponentInstance struct {
val C.wasmtime_component_instance_t
}
func mkComponentInstance(val C.wasmtime_component_instance_t) *ComponentInstance {
return &ComponentInstance{val: val}
}
// GetExportIndex looks up the export named `name` in this instance and
// returns a reusable [ComponentExportIndex] handle pointing at it. The
// `parent` argument behaves the same way as in [Component.GetExportIndex]
// (`nil` for the root namespace; an instance index for nested traversal).
// Returns `nil` if no matching export is found.
//
// Use this when the export you want lives inside an instantiated
// [ComponentInstance] rather than statically inside the [Component].
func (i *ComponentInstance) GetExportIndex(store Storelike, parent *ComponentExportIndex, name string) *ComponentExportIndex {
var parentPtr *C.wasmtime_component_export_index_t
if parent != nil {
parentPtr = parent.ptr()
}
idxPtr := C.wasmtime_component_instance_get_export_index(
&i.val,
store.Context(),
parentPtr,
C._GoStringPtr(name),
C._GoStringLen(name),
)
runtime.KeepAlive(i)
runtime.KeepAlive(store)
runtime.KeepAlive(parent)
runtime.KeepAlive(name)
if idxPtr == nil {
return nil
}
return mkComponentExportIndex(idxPtr)
}