functionalscript 0.0.414 → 0.0.415
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/com/rust/nanocom/README.md +54 -1
- package/package.json +1 -1
|
@@ -1,3 +1,56 @@
|
|
|
1
1
|
# Nano-COM
|
|
2
2
|
|
|
3
|
-
See [Nano-COM](https://en.wikipedia.org/wiki/Component_Object_Model#Nano-COM_(a.k.a_XPCOM)).
|
|
3
|
+
See [Nano-COM](https://en.wikipedia.org/wiki/Component_Object_Model#Nano-COM_(a.k.a_XPCOM)).
|
|
4
|
+
|
|
5
|
+
## Function Stack
|
|
6
|
+
|
|
7
|
+
- a public function.
|
|
8
|
+
```rust
|
|
9
|
+
let o: Object<IMy> = ...;
|
|
10
|
+
// calling a public function
|
|
11
|
+
let i: u32 = o.B();
|
|
12
|
+
```
|
|
13
|
+
```rust
|
|
14
|
+
trait IMyEx {
|
|
15
|
+
// a definition
|
|
16
|
+
fn B(&self) -> u32;
|
|
17
|
+
}
|
|
18
|
+
impl IMyEx for Object<IMy> {
|
|
19
|
+
// an implementation of the public function
|
|
20
|
+
fn B(&self) -> u32 {
|
|
21
|
+
// calling a virtual function.
|
|
22
|
+
unsafe { (self.interface().B()(self) }
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
- a virtual function.
|
|
27
|
+
```rust
|
|
28
|
+
#[repr(C)]
|
|
29
|
+
pub struct IMy {
|
|
30
|
+
// a definiton of the virtual function
|
|
31
|
+
pub B: unsafe extern "stdcall" fn(this: &Object<IMy>) -> u32
|
|
32
|
+
}
|
|
33
|
+
trait IMyVmtFn: Class<Interface = IMy>
|
|
34
|
+
where
|
|
35
|
+
CObject<Self>: IMyEx
|
|
36
|
+
{
|
|
37
|
+
// an implementation of the virtual function
|
|
38
|
+
extern "stdcall" fn B(this: &Object<IMy>) -> u32 {
|
|
39
|
+
// calling a function implementation
|
|
40
|
+
unsafe { Self::to_cobject(this) }.B()
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
- a function implementation.
|
|
45
|
+
```rust
|
|
46
|
+
trait IMyEx {
|
|
47
|
+
// a definition
|
|
48
|
+
fn B(&self) -> u32;
|
|
49
|
+
}
|
|
50
|
+
impl IMyEx for CObject<X> {
|
|
51
|
+
// an implementation of the function.
|
|
52
|
+
fn B(&self) -> u32 {
|
|
53
|
+
self.value.0
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|