LuaLS / LuaLS/lua-language-server

feature: Variadic generic packs and mapping expansion

Open
#2,470 0 comments 4 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.