create call and call_args methods for BotFunction
This commit is contained in:
parent
0dc71fda08
commit
d1b6d153d4
@ -24,6 +24,8 @@ pub enum ScriptError {
|
|||||||
SerdeError(#[from] quickjs_rusty::serde::Error),
|
SerdeError(#[from] quickjs_rusty::serde::Error),
|
||||||
#[error("error value: {0:?}")]
|
#[error("error value: {0:?}")]
|
||||||
ValueError(#[from] ValueError),
|
ValueError(#[from] ValueError),
|
||||||
|
#[error("error bot function execution: {0:?}")]
|
||||||
|
BotFunctionError(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type ScriptResult<T> = Result<T, ScriptError>;
|
pub type ScriptResult<T> = Result<T, ScriptError>;
|
||||||
@ -98,6 +100,21 @@ impl BotFunction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn call(&self) -> ScriptResult<JsValue> {
|
||||||
|
self.call_args(Default::default())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn call_args(&self, args: Vec<JsValue>) -> ScriptResult<JsValue> {
|
||||||
|
if let FunctionMarker::Function(f) = &self.func {
|
||||||
|
let val = f.call(args)?;
|
||||||
|
Ok(val)
|
||||||
|
} else {
|
||||||
|
Err(ScriptError::BotFunctionError(
|
||||||
|
"Js Function is not defined".to_string(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_js_function(&mut self, f: JsFunction) {
|
pub fn set_js_function(&mut self, f: JsFunction) {
|
||||||
self.func.set_js_function(f);
|
self.func.set_js_function(f);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user