diff --git a/src/lua.rs b/src/lua.rs index 5c35eb3..acf8f08 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -35,6 +35,23 @@ impl Lua { } } + pub fn call_function(&self, name: &str, nargs: i32) -> Result<(), Error> { + let c_name = CString::new(name).map_err(Error::msg)?; + let mut out_err: *const crankstart_sys::ctypes::c_char = ptr::null_mut(); + pd_func_caller!( + (*self.0).callFunction, + c_name.as_ptr(), + nargs as ctypes::c_int, + &mut out_err + )?; + if !out_err.is_null() { + let err_msg = unsafe { CStr::from_ptr(out_err).to_string_lossy().into_owned() }; + Err(anyhow!(err_msg)) + } else { + Ok(()) + } + } + pub fn get_arg_string(&self, pos: i32) -> Result { let c_arg_string = pd_func_caller!((*self.0).getArgString, pos as ctypes::c_int)?; unsafe { @@ -42,4 +59,8 @@ impl Lua { Ok(arg_string) } } + + pub fn push_function(&self, f: lua_CFunction) -> Result<(), Error> { + pd_func_caller!((*self.0).pushFunction, f) + } }