From d1b6d153d4ed57b0ff9a3df1f4f5ac76c6119d06 Mon Sep 17 00:00:00 2001 From: Akulij Date: Wed, 21 May 2025 12:53:26 +0500 Subject: [PATCH] create call and call_args methods for BotFunction --- src/botscript.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/botscript.rs b/src/botscript.rs index b961002..f52ab6c 100644 --- a/src/botscript.rs +++ b/src/botscript.rs @@ -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 = Result; @@ -98,6 +100,21 @@ impl BotFunction { } } + pub fn call(&self) -> ScriptResult { + self.call_args(Default::default()) + } + + pub fn call_args(&self, args: Vec) -> ScriptResult { + 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); }