[−][src]Struct runestick::Module
A collection of functions that can be looked up by type.
Implementations
impl Module
[src]
pub fn new<I>(path: I) -> Self where
I: IntoIterator,
I::Item: Into<Component>,
[src]
I: IntoIterator,
I::Item: Into<Component>,
Construct a new module.
pub fn ty<N>(&mut self, name: N) -> TypeBuilder<'_, N> where
N: IntoIterator,
N::Item: Into<Component>,
[src]
N: IntoIterator,
N::Item: Into<Component>,
Register a type.
This will allow the type to be used within scripts, using the item named here.
pub fn unit<N>(&mut self, name: N) -> Result<(), ContextError> where
N: IntoIterator,
N::Item: Into<Component>,
[src]
N: IntoIterator,
N::Item: Into<Component>,
Construct the option type.
pub fn option<N>(&mut self, name: N) -> Result<(), ContextError> where
N: IntoIterator,
N::Item: Into<Component>,
[src]
N: IntoIterator,
N::Item: Into<Component>,
Construct the option type.
pub fn result<N>(&mut self, name: N) -> Result<(), ContextError> where
N: IntoIterator,
N::Item: Into<Component>,
[src]
N: IntoIterator,
N::Item: Into<Component>,
Construct the result type.
pub fn generator_state<N>(&mut self, name: N) -> Result<(), ContextError> where
N: IntoIterator,
N::Item: Into<Component>,
[src]
N: IntoIterator,
N::Item: Into<Component>,
Construct the type information for the GeneratorState
type.
pub fn function<Func, Args, N>(
&mut self,
name: N,
f: Func
) -> Result<(), ContextError> where
Func: Function<Args>,
N: IntoIterator,
N::Item: Into<Component>,
[src]
&mut self,
name: N,
f: Func
) -> Result<(), ContextError> where
Func: Function<Args>,
N: IntoIterator,
N::Item: Into<Component>,
Register a function that cannot error internally.
Examples
use std::collections::VecDeque; #[derive(Debug, Clone)] struct StringQueue(VecDeque<String>); impl StringQueue { fn new() -> Self { Self(VecDeque::new()) } } runestick::decl_external!(StringQueue); let mut module = runestick::Module::default(); module.function(&["bytes"], StringQueue::new)?; module.function(&["empty"], || Ok::<_, runestick::Error>(()))?; module.function(&["string"], |a: String| Ok::<_, runestick::Error>(()))?; module.function(&["optional"], |a: Option<String>| Ok::<_, runestick::Error>(()))?;
pub fn async_function<Func, Args, N>(
&mut self,
name: N,
f: Func
) -> Result<(), ContextError> where
Func: AsyncFunction<Args>,
N: IntoIterator,
N::Item: Into<Component>,
[src]
&mut self,
name: N,
f: Func
) -> Result<(), ContextError> where
Func: AsyncFunction<Args>,
N: IntoIterator,
N::Item: Into<Component>,
Register a function.
Examples
let mut module = runestick::Module::default(); module.async_function(&["empty"], || async { () })?; module.async_function(&["empty_fallible"], || async { Ok::<_, runestick::Error>(()) })?; module.async_function(&["string"], |a: String| async { Ok::<_, runestick::Error>(()) })?; module.async_function(&["optional"], |a: Option<String>| async { Ok::<_, runestick::Error>(()) })?;
pub fn raw_fn<F, N>(&mut self, name: N, f: F) -> Result<(), ContextError> where
F: 'static + Copy + Fn(&mut Stack, usize) -> Result<(), VmError> + Send + Sync,
N: IntoIterator,
N::Item: Into<Component>,
[src]
F: 'static + Copy + Fn(&mut Stack, usize) -> Result<(), VmError> + Send + Sync,
N: IntoIterator,
N::Item: Into<Component>,
Register a raw function which interacts directly with the virtual machine.
pub fn inst_fn<N, Func, Args>(
&mut self,
name: N,
f: Func
) -> Result<(), ContextError> where
N: IntoInstFnHash,
Func: InstFn<Args>,
[src]
&mut self,
name: N,
f: Func
) -> Result<(), ContextError> where
N: IntoInstFnHash,
Func: InstFn<Args>,
Register an instance function.
Examples
use std::collections::VecDeque; #[derive(Debug, Clone)] struct StringQueue(VecDeque<String>); impl StringQueue { fn new() -> Self { Self(VecDeque::new()) } fn len(&self) -> usize { self.0.len() } } runestick::decl_external!(StringQueue); let mut module = runestick::Module::default(); module.ty(&["StringQueue"]).build::<StringQueue>()?; module.function(&["StringQueue", "bytes"], StringQueue::new)?; module.inst_fn("len", StringQueue::len)?;
pub fn getter<N, Func, Args>(
&mut self,
name: N,
f: Func
) -> Result<(), ContextError> where
N: IntoInstFnHash,
Func: InstFn<Args>,
[src]
&mut self,
name: N,
f: Func
) -> Result<(), ContextError> where
N: IntoInstFnHash,
Func: InstFn<Args>,
Install a getter for the specified field.
pub fn async_inst_fn<N, Func, Args>(
&mut self,
name: N,
f: Func
) -> Result<(), ContextError> where
N: IntoInstFnHash,
Func: AsyncInstFn<Args>,
[src]
&mut self,
name: N,
f: Func
) -> Result<(), ContextError> where
N: IntoInstFnHash,
Func: AsyncInstFn<Args>,
Register an instance function.
Examples
use std::sync::atomic::AtomicU32; use std::sync::Arc; runestick::decl_external!(MyType); #[derive(Clone, Debug)] struct MyType { value: Arc<AtomicU32>, } impl MyType { async fn test(&self) -> runestick::Result<()> { Ok(()) } } let mut module = runestick::Module::default(); module.ty(&["MyType"]).build::<MyType>()?; module.async_inst_fn("test", MyType::test)?;
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Module
impl !Send for Module
impl !Sync for Module
impl Unpin for Module
impl !UnwindSafe for Module
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,