Skip to content
This repository has been archived by the owner on Oct 21, 2023. It is now read-only.

指令系统设想 #10

Open
LaoLittle opened this issue Dec 16, 2022 · 1 comment
Open

指令系统设想 #10

LaoLittle opened this issue Dec 16, 2022 · 1 comment

Comments

@LaoLittle
Copy link
Owner

LaoLittle commented Dec 16, 2022

指令系统

单指令

单个可以执行的指令

#[command(name = "x", help="a")]
async fn a(arg1: ..) -> Result<(), ?> {

}

调用方式: /x arg1..

复合指令

#[command(name = "x")]
mod a {
  #[command(name = "y")]
  fn b() {}
  
  #[command(name = "z")]
  mod c {}
}

调用方式: /x y or /x z ...

指令执行器

所有的指令应先注册到执行器
然后由执行器统一执行

指令参数分析器

参数与参数间应有空格
将消息隔开并迭代, 尝试将字符串一个个解析为对应的参数
失败则不执行此指令

定义trait CommandArg, 要求参数实现CommandArg

宏生成后的代码类似:

let mut iter = cmd.split(' ');
a(
  <A as CommandArg>::from_str(iter.next()?)?,
  <B as CommandArg>::from_str(iter.next()?)?,
  <C as CommandArg>::from_str(iter.next()?)?,
).await

对于同步函数,应额外加上block_in_place

FFI

暴露指令注册函数
函数应为同步函数或异步函数(返回FFIFuture)

union CommandUnion {
  fun: extern "C" fn(..),
  async_fun: extern "C" fn(..) -> FFIFuture,
  set: RustVec<FFICommand>,
}

struct FFICommand {
  name: RustStr,
  type: u8, // 0: sync, 1: async, 2: complex
  inner: CommandUnion
}
@LaoLittle
Copy link
Owner Author

应简化指令系统,将参数直接传入,将只支持纯文本. 参考程序main函数

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant