migration to JS engine #1
@ -24,6 +24,8 @@ pub enum ScriptError {
|
||||
SerdeError(#[from] quickjs_rusty::serde::Error),
|
||||
#[error("error value: {0:?}")]
|
||||
ValueError(#[from] ValueError),
|
||||
#[error("error bot function execution: {0:?}")]
|
||||
BotFunctionError(String),
|
||||
}
|
||||
|
||||
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) {
|
||||
self.func.set_js_function(f);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user