-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathaddin2.rs
77 lines (68 loc) · 1.82 KB
/
addin2.rs
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
67
68
69
70
71
72
73
74
75
76
77
use addin1c::{name, MethodInfo, Methods, ParamValue, PropInfo, SimpleAddin, Variant};
pub struct Addin2 {
prop1: i32,
}
impl Addin2 {
pub fn new() -> Addin2 {
Addin2 { prop1: 0 }
}
fn method1(&mut self, param: &mut Variant, ret_value: &mut Variant) -> bool {
let ParamValue::I32(value) = param.get() else {
return false;
};
self.prop1 = value;
ret_value.set_i32(value * 2);
true
}
fn method2(
&mut self,
param1: &mut Variant,
param2: &mut Variant,
ret_value: &mut Variant,
) -> bool {
let ParamValue::I32(value1) = param1.get() else {
return false;
};
let ParamValue::I32(value2) = param2.get() else {
return false;
};
self.prop1 = value1 + value2;
ret_value.set_i32(self.prop1);
true
}
fn set_prop1(&mut self, value: &ParamValue) -> bool {
let ParamValue::I32(value) = value else {
return false;
};
self.prop1 = *value;
true
}
fn get_prop1(&mut self, value: &mut Variant) -> bool {
value.set_i32(self.prop1);
true
}
}
impl SimpleAddin for Addin2 {
fn name() -> &'static [u16] {
name!("Class2")
}
fn methods() -> &'static [MethodInfo<Self>] {
&[
MethodInfo {
name: name!("Method1"),
method: Methods::Method1(Self::method1),
},
MethodInfo {
name: name!("Method2"),
method: Methods::Method2(Self::method2),
},
]
}
fn properties() -> &'static [PropInfo<Self>] {
&[PropInfo {
name: name!("Prop1"),
getter: Some(Self::get_prop1),
setter: Some(Self::set_prop1),
}]
}
}