1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use std::ffi::CStr;
use crate::base::mathfunc;
unsafe impl Sync for mathfunc {}
unsafe impl Send for mathfunc {}
impl mathfunc {
/// Creates a new `mathfunc` that gets an array of mnumbers (the zsh type for representing values in arithmetic expressions) taken from the string in parentheses at the function call.
///
/// Like `NUMMATHFUNC` in zsh's C code.
///
/// # Args
/// - `name`: The name of the mathfunc command.
/// - `handler`: The handler function for the mathfunc command.
/// - `minargs`: The minimum number of arguments the mathfunc command accepts.
/// - `maxargs`: The maximum number of arguments the mathfunc command accepts.
/// - `id`: The unique identifier for the mathfunc command. Can be used to distinguish between different mathfuncs using the same handler function.
///
pub const fn new_num(
name: &'static CStr,
handler: super::types::NumMathFuncInner,
minargs: i32,
maxargs: i32,
id: i32,
) -> Self {
Self {
next: std::ptr::null_mut(),
name: name.as_ptr() as _,
flags: 0,
nfunc: Some(handler),
sfunc: None,
module: std::ptr::null_mut(),
minargs,
maxargs,
funcid: id,
}
}
/// Creates a new `mathfunc` that gets the string in parentheses at the call as one string argument (without the parentheses)
///
/// Like `STRMATHFUNC` in zsh's C code.
///
/// # Args
/// - `name`: The name of the mathfunc command.
/// - `handler`: The handler function for the mathfunc command.
/// - `id`: The unique identifier for the mathfunc command. Can be used to distinguish between different mathfuncs using the same handler function.
///
pub const fn new_str(
name: &'static CStr,
handler: super::types::StrMathFuncInner,
id: i32,
) -> Self {
Self {
next: std::ptr::null_mut(),
name: name.as_ptr() as _,
flags: crate::base::MFF_STR as _,
nfunc: None,
sfunc: Some(handler),
module: std::ptr::null_mut(),
minargs: 0,
maxargs: 0,
funcid: id,
}
}
}