|
1 | | -use crate::externals::{Export, Extern}; |
| 1 | +use crate::externals::{Export, Extern, Global, Memory, Table}; |
| 2 | +use crate::func::Func; |
2 | 3 | use crate::module::Module; |
3 | 4 | use crate::runtime::{Config, Store}; |
4 | 5 | use crate::trap::Trap; |
@@ -188,6 +189,38 @@ impl Instance { |
188 | 189 | )) |
189 | 190 | } |
190 | 191 |
|
| 192 | + /// Looks up an exported [`Func`] value by name. |
| 193 | + /// |
| 194 | + /// Returns `None` if there was no export named `name`, or if there was but |
| 195 | + /// it wasn't a function. |
| 196 | + pub fn get_func(&self, name: &str) -> Option<Func> { |
| 197 | + self.get_export(name)?.into_func() |
| 198 | + } |
| 199 | + |
| 200 | + /// Looks up an exported [`Table`] value by name. |
| 201 | + /// |
| 202 | + /// Returns `None` if there was no export named `name`, or if there was but |
| 203 | + /// it wasn't a table. |
| 204 | + pub fn get_table(&self, name: &str) -> Option<Table> { |
| 205 | + self.get_export(name)?.into_table() |
| 206 | + } |
| 207 | + |
| 208 | + /// Looks up an exported [`Memory`] value by name. |
| 209 | + /// |
| 210 | + /// Returns `None` if there was no export named `name`, or if there was but |
| 211 | + /// it wasn't a memory. |
| 212 | + pub fn get_memory(&self, name: &str) -> Option<Memory> { |
| 213 | + self.get_export(name)?.into_memory() |
| 214 | + } |
| 215 | + |
| 216 | + /// Looks up an exported [`Global`] value by name. |
| 217 | + /// |
| 218 | + /// Returns `None` if there was no export named `name`, or if there was but |
| 219 | + /// it wasn't a global. |
| 220 | + pub fn get_global(&self, name: &str) -> Option<Global> { |
| 221 | + self.get_export(name)?.into_global() |
| 222 | + } |
| 223 | + |
191 | 224 | #[doc(hidden)] |
192 | 225 | pub fn handle(&self) -> &InstanceHandle { |
193 | 226 | &self.instance_handle |
|
0 commit comments