LuaLS / LuaLS/lua-language-server
feature: Variadic generic packs and mapping expansion
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
#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:
```lua
---@generic R, T...
---@param fn fun(...: T...):R
---@param ... Component
---@return System
function System.new(fn, ...)
...
end
---@generic R
---@param System 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the related issue #1861 and the proposed Lua examples in this issue. Define how variadic generic packs, mapping expansion, and the `...` shorthand should behave, then verify that the demonstrated System API can express typed component parameters and return values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100