migration to JS engine #1

Merged
akulij merged 131 commits from dev into main 2025-05-31 08:49:52 +00:00
Showing only changes of commit d1b6d153d4 - Show all commits

View File

@ -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);
}