functionalscript 0.0.462 → 0.0.464

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.
@@ -19,10 +19,13 @@ jobs:
19
19
  runs-on: ${{ matrix.os }}
20
20
 
21
21
  steps:
22
- - uses: actions/checkout@v2
22
+ - uses: actions/checkout@v3
23
23
  - name: Use Node.js 19
24
24
  uses: actions/setup-node@v2
25
25
  with:
26
26
  node-version: 19
27
+ - uses: actions/setup-dotnet@v3
28
+ with:
29
+ dotnet-version: 7
27
30
  - run: npm ci
28
31
  - run: npm run comtest
package/Cargo.lock CHANGED
@@ -4,7 +4,7 @@ version = 3
4
4
 
5
5
  [[package]]
6
6
  name = "nanocom"
7
- version = "0.2.0"
7
+ version = "0.2.1"
8
8
 
9
9
  [[package]]
10
10
  name = "testrust"
package/com/cpp/com.hpp CHANGED
@@ -21,7 +21,12 @@ namespace com
21
21
  };
22
22
 
23
23
  typedef uint32_t HRESULT;
24
+
25
+ static HRESULT const E_NOINTERFACE = 0x80004002;
26
+ static HRESULT const S_OK = 0;
27
+
24
28
  typedef uint32_t ULONG;
29
+
25
30
  typedef int32_t BOOL;
26
31
 
27
32
  class IUnknown
@@ -32,7 +37,7 @@ namespace com
32
37
  virtual ULONG COM_STDCALL Release() noexcept = 0;
33
38
  };
34
39
 
35
- template <class I>
40
+ template<class I>
36
41
  class ref
37
42
  {
38
43
  public:
@@ -50,4 +55,21 @@ namespace com
50
55
  private:
51
56
  I &p;
52
57
  };
58
+
59
+ template<class I>
60
+ class implementation: public I
61
+ {
62
+ HRESULT COM_STDCALL QueryInterface(GUID const &riid, IUnknown **const ppvObject) noexcept override
63
+ {
64
+ return E_NOINTERFACE;
65
+ }
66
+ ULONG COM_STDCALL AddRef() noexcept override
67
+ {
68
+ return 0;
69
+ }
70
+ ULONG COM_STDCALL Release() noexcept override
71
+ {
72
+ return 0;
73
+ }
74
+ };
53
75
  }
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "nanocom"
3
- version = "0.2.0"
3
+ version = "0.2.1"
4
4
  edition = "2021"
5
5
  description = "Nano-COM, extremly small subset of cross-platform COM"
6
6
  authors = ["NatFoam"]
@@ -3,7 +3,7 @@ use std::{
3
3
  sync::atomic::{AtomicU32, Ordering},
4
4
  };
5
5
 
6
- use crate::{hresult::HRESULT, iunknown::IUnknown, Class, Interface, Object, Ref, Vmt};
6
+ use crate::{guid::GuidEx, hresult::HRESULT, iunknown::IUnknown, Class, Object, Ref};
7
7
 
8
8
  #[repr(C)]
9
9
  pub struct CObject<T: Class> {
@@ -12,14 +12,6 @@ pub struct CObject<T: Class> {
12
12
  pub value: T,
13
13
  }
14
14
 
15
- const fn guid<I: Interface>() -> u128 {
16
- let x = <I>::GUID;
17
- (x >> 96) |
18
- ((x >> 48) & 0x00000_000_0000_0000_0000_FFFF_0000_0000) |
19
- ((x >> 16) & 0x0000_0000_0000_0000_FFFF_0000_0000_0000) |
20
- (((x as u64).swap_bytes() as u128) << 64)
21
- }
22
-
23
15
  impl<T: Class> CObject<T> {
24
16
  pub const IUNKNOWN: IUnknown<T::Interface> = IUnknown {
25
17
  QueryInterface: Self::QueryInterface,
@@ -38,7 +30,7 @@ impl<T: Class> CObject<T> {
38
30
  riid: &u128,
39
31
  ppv_object: &mut *const Object,
40
32
  ) -> HRESULT {
41
- let (p, r) = if *riid == guid::<()>() || *riid == guid::<T::Interface>() {
33
+ let (p, r) = if *riid == <()>::PLATFORM_GUID || *riid == T::Interface::PLATFORM_GUID {
42
34
  Self::AddRef(this);
43
35
  (this.to_iunknown() as *const Object, HRESULT::S_OK)
44
36
  } else {
@@ -1 +1,15 @@
1
+ use crate::Interface;
2
+
1
3
  pub type GUID = u128;
4
+
5
+ pub trait GuidEx: Interface {
6
+ const PLATFORM_GUID: GUID = {
7
+ let x = Self::GUID;
8
+ (x >> 96)
9
+ | ((x >> 48) & 0x00000_000_0000_0000_0000_FFFF_0000_0000)
10
+ | ((x >> 16) & 0x0000_0000_0000_0000_FFFF_0000_0000_0000)
11
+ | (((x as u64).swap_bytes() as u128) << 64)
12
+ };
13
+ }
14
+
15
+ impl<T: Interface> GuidEx for T {}
@@ -77,13 +77,17 @@ const cpp = ({dirname, platform}) => ({
77
77
  })
78
78
 
79
79
  /** @type {Func} */
80
- const cs = ({dirname}) => ({
80
+ const cs = ({dirname, platform}) => ({
81
81
  file: {
82
82
  name: `${dirname}/cs/_result.cs`,
83
83
  content: csContent,
84
84
  },
85
85
  line: [
86
- ['dotnet', 'run', '--project', `${dirname}/cs/cs.csproj`]],
86
+ platform === 'win32'
87
+ ? ['dotnet', 'run', '--project', `${dirname}/cs/cs.csproj`]
88
+ // .Net on Linux and Windows doesn't properly support COM object marshalling
89
+ : ['dotnet', 'build', `${dirname}/cs/cs.csproj`]
90
+ ],
87
91
  })
88
92
 
89
93
  /** @type {Func} */
@@ -12,3 +12,34 @@ extern "C" int c_get()
12
12
  {
13
13
  return 43;
14
14
  }
15
+
16
+ class Impl: public com::implementation<My::IMy>
17
+ {
18
+ My::Slice COM_STDCALL GetSlice() noexcept override
19
+ {
20
+ }
21
+ void COM_STDCALL SetSlice(My::Slice slice) noexcept override
22
+ {
23
+ }
24
+ ::com::BOOL *COM_STDCALL GetUnsafe() noexcept override
25
+ {
26
+ }
27
+ void COM_STDCALL SetUnsafe(My::Slice *p, uint32_t size) noexcept override
28
+ {
29
+ }
30
+ ::com::BOOL COM_STDCALL Some(My::IMy &p) noexcept override
31
+ {
32
+ }
33
+ ::com::ref<My::IMy> COM_STDCALL GetIMy() noexcept override
34
+ {
35
+ }
36
+ void COM_STDCALL SetManagedStruct(My::ManagedStruct a) noexcept override
37
+ {
38
+ }
39
+ };
40
+
41
+ DLL_EXPORT
42
+ extern "C" My::IMy* c_my_create()
43
+ {
44
+ return new Impl();
45
+ }
@@ -46,9 +46,11 @@ impl _result::IMy::Ex for nanocom::CObject<My> {
46
46
  }
47
47
 
48
48
  #[no_mangle]
49
- pub extern "C" fn get() -> i32 { 42 }
49
+ pub extern "C" fn get() -> i32 {
50
+ 42
51
+ }
50
52
 
51
53
  #[no_mangle]
52
54
  pub extern "C" fn rust_my_create() -> IMy::Ref {
53
55
  My {}.to_cobject()
54
- }
56
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.462",
3
+ "version": "0.0.464",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {