This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
use crate::script_implementations::rune::wrappers::{impl_rune_wrapper, RuneStringKey, RuneWrapper};
|
||||
use crate::static_data::Ability;
|
||||
use rune::runtime::{AnyObj, Shared};
|
||||
use rune::Any;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub fn register(module: &mut rune::Module) -> anyhow::Result<()> {
|
||||
module.ty::<RuneAbility>()?;
|
||||
module.function_meta(RuneAbility::name)?;
|
||||
module.function_meta(RuneAbility::effect)?;
|
||||
module.function_meta(RuneAbility::get_parameter)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Debug, Any)]
|
||||
pub struct RuneAbility(Arc<dyn Ability>);
|
||||
|
||||
impl_rune_wrapper!(&Arc<dyn Ability>, RuneAbility);
|
||||
|
||||
impl RuneAbility {
|
||||
#[rune::function]
|
||||
fn name(&self) -> Shared<AnyObj> { self.0.name().wrap() }
|
||||
|
||||
#[rune::function]
|
||||
fn effect(&self) -> Shared<AnyObj> { self.0.effect().wrap() }
|
||||
|
||||
#[rune::function(vm_result)]
|
||||
fn get_parameter(&self, key: RuneStringKey) -> Option<Shared<AnyObj>> {
|
||||
match self.0.parameters().get(&key.0) {
|
||||
None => None,
|
||||
Some(p) => Some(p.wrap()),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user