1*ce3c1a72SMangoPeachGrape use wasmtime::component::{Func, Instance};
2*ce3c1a72SMangoPeachGrape
3*ce3c1a72SMangoPeachGrape use crate::WasmtimeStoreContextMut;
4*ce3c1a72SMangoPeachGrape
5*ce3c1a72SMangoPeachGrape use super::wasmtime_component_export_index_t;
6*ce3c1a72SMangoPeachGrape
7*ce3c1a72SMangoPeachGrape #[unsafe(no_mangle)]
wasmtime_component_instance_get_export_index( instance: &Instance, context: WasmtimeStoreContextMut<'_>, instance_export_index: *const wasmtime_component_export_index_t, name: *const u8, name_len: usize, ) -> Option<Box<wasmtime_component_export_index_t>>8*ce3c1a72SMangoPeachGrape pub unsafe extern "C" fn wasmtime_component_instance_get_export_index(
9*ce3c1a72SMangoPeachGrape instance: &Instance,
10*ce3c1a72SMangoPeachGrape context: WasmtimeStoreContextMut<'_>,
11*ce3c1a72SMangoPeachGrape instance_export_index: *const wasmtime_component_export_index_t,
12*ce3c1a72SMangoPeachGrape name: *const u8,
13*ce3c1a72SMangoPeachGrape name_len: usize,
14*ce3c1a72SMangoPeachGrape ) -> Option<Box<wasmtime_component_export_index_t>> {
15*ce3c1a72SMangoPeachGrape let name = unsafe { std::slice::from_raw_parts(name, name_len) };
16*ce3c1a72SMangoPeachGrape let Ok(name) = std::str::from_utf8(name) else {
17*ce3c1a72SMangoPeachGrape return None;
18*ce3c1a72SMangoPeachGrape };
19*ce3c1a72SMangoPeachGrape
20*ce3c1a72SMangoPeachGrape let instance_export_index = if instance_export_index.is_null() {
21*ce3c1a72SMangoPeachGrape None
22*ce3c1a72SMangoPeachGrape } else {
23*ce3c1a72SMangoPeachGrape Some((*instance_export_index).export_index)
24*ce3c1a72SMangoPeachGrape };
25*ce3c1a72SMangoPeachGrape
26*ce3c1a72SMangoPeachGrape instance
27*ce3c1a72SMangoPeachGrape .get_export_index(context, instance_export_index.as_ref(), &name)
28*ce3c1a72SMangoPeachGrape .map(|export_index| Box::new(wasmtime_component_export_index_t { export_index }))
29*ce3c1a72SMangoPeachGrape }
30*ce3c1a72SMangoPeachGrape
31*ce3c1a72SMangoPeachGrape #[unsafe(no_mangle)]
wasmtime_component_instance_get_func( instance: &Instance, context: WasmtimeStoreContextMut<'_>, export_index: &wasmtime_component_export_index_t, func_out: &mut Func, ) -> bool32*ce3c1a72SMangoPeachGrape pub unsafe extern "C" fn wasmtime_component_instance_get_func(
33*ce3c1a72SMangoPeachGrape instance: &Instance,
34*ce3c1a72SMangoPeachGrape context: WasmtimeStoreContextMut<'_>,
35*ce3c1a72SMangoPeachGrape export_index: &wasmtime_component_export_index_t,
36*ce3c1a72SMangoPeachGrape func_out: &mut Func,
37*ce3c1a72SMangoPeachGrape ) -> bool {
38*ce3c1a72SMangoPeachGrape if let Some(func) = instance.get_func(context, export_index.export_index) {
39*ce3c1a72SMangoPeachGrape *func_out = func;
40*ce3c1a72SMangoPeachGrape true
41*ce3c1a72SMangoPeachGrape } else {
42*ce3c1a72SMangoPeachGrape false
43*ce3c1a72SMangoPeachGrape }
44*ce3c1a72SMangoPeachGrape }
45