Replies: 1 comment
-
做了一小部分 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
目标
通过IDL定义接口,然后使用代码生成器生成胶水代码,实现MaaCore和其他语言的(进程内)面向对象的双向互操作。后续暴露 RMI 接口供 Node/Python 等不便通过 FFI 实现进程内接口的语言/框架使用。
参考
类型系统
基本类型
组合类型
接口与实例
泛型接口(?)
允许为不同类型定义相似的接口,避免在 IDL 中复读接口定义。参考 https://learn.microsoft.com/en-us/uwp/winrt-cref/winrt-type-system#parameterized-interfaces
委托(回调)
委托(回调)是由希望接收通知一方实现的指定接口,成员仅包含一个方法。
(或者仿照 Java 模式,直接使用接口?)
事件
基于委托的更高一层抽象,定义方式待定:
可以实现为实例上的接口,如
或者使用类 GObject 模式,通过全局函数注册
接口定义语言(IDL)
选择易于通过程序结构化获取各个成员定义的语言作为 IDL,如 C# 或 Java:
进程内 ABI
参考 https://learn.microsoft.com/en-us/uwp/winrt-cref/winrt-type-system#interface-members
关键点:
基于 COM ABI,即
全局函数:
MaaRtAlloc
/MaaRtFree
:统一的内存分配/释放入口MString
:ABI 字符串(类似JNI及HSTRING)\0
,允许中间存在\0
MaaRtCreateString
函数创建字符串对象(复制数据),返回MString
不透明指针MaaRtDuplicateString
函数增加引用计数MaaRtDeleteString
函数减少引用计数MaaRtGetStringData
获得长度以及数据MaaRtSubString
提取子字符串(根据大小决定增加引用计数或进行复制)MaaRtSetLastError
/MaaRtGetLastError
:考虑到没有人想给每个可能的错误编码错误代码,通过这组函数设置和获取错误信息(字符串)
函数参数约定
void
,最后一个参数为返回值出参MString
不透明指针传递T *first, uint64 length
T **first, uint64 *length
,由被调用方申请内存,调用方使用 MaaRtFree 释放。Beta Was this translation helpful? Give feedback.
All reactions