LuaLS / LuaLS/lua-language-server
feature: Variadic generic packs and mapping expansion
还没有人认领这个 Issue。
- 主要语言
- Lua
- 星标
- 4.4k
- 派生
- 442
- PR 合并指标
- 30 天内没有已合并 PR
描述
#1861
This feature request requests variadic generics functionality, as well as mapping those generics. My proposed implementation of this feature request would allow the following example syntax:
---@generic R, T...
---@param fn fun(...: T...):R
---@param ... Component<T>
---@return System<R>
function System.new(fn, ...)
...
end
---@generic R
---@param System<R> self
---@param entities Entity[]
---@return R[]
function System:run()
...
end
The example code above also introduces a shorthand for variadics (line 3): whenever the parameter ... would have an unexpanded parameter pack as an argument, it is implicitly expanded. Any type can be expanded at any point by suffixing a ..., as shown in line 2.
The motivation of this request arises from an well-typed ECS implementation with object-oriented systems. Without variadic generics, it is not possible in any way I know of to allow a system to depend on any amount of components and still have well-typed parameters.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从相关 issue #1861 以及本 issue 中提出的 Lua 示例开始。定义可变参数泛型包、映射展开和 ... 简写应如何工作,然后验证所演示的 System API 是否能够表达带类型的组件参数和返回值。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- lua
- 领域
- devtools
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 30/100