Feature Request: ability to overload the return value type
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 45/100
Direzione di ricerca
Inizia tracciando il modo in cui il server del linguaggio rappresenta i valori di ritorno multipli annotati e li verifica nei siti di chiamata. Usa l’esempio ECS nell’issue come comportamento da analizzare, inclusi i casi con zero e due valori. Il lavoro è completato quando un’annotazione supportata può esprimere valori di ritorno multivalore all-or-nothing o uniti, senza richiedere il cast mostrato, e la diagnostica è coperta per entrambi i casi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
Which OS are you using?
macOS
What is the issue affecting?
Annotations
Feature request
In my game's ECS bindings I have getter functions that work like this:
---@param id integer
---@return number? inv_mass
---@return number? restitution
function ecs.get_collision_body_values(id) end
local inv_mass, restitution = ecs.get_collision_body_values(entity_id)
This calls into a native ECS implementation that either pushes the 2 return values and returns with return 2; (2 return values) or if the return values doesn't exist, push nothing and return 0; (zero return values).
This can be used in my game code like this:
local function debug_body(id)
local inv_mass, restitution = ecs.get_collision_body_values(id)
if inv_mass == nil then -- collision_body component not set, do nothing
return
end
---@cast restitution number
-- ^^ have to cast restitution number? -> number to avoid warning
print(inv_mass, restitution)
end
Would be nice if there was a way to annotate an "all or nothing" multiple return value type. E.g., a function will either return multiple return values (e.g., not number? but number) or that it will return nothing. Or I guess more generally, the ability to somehow specify a union of different multivalue return types.
FWIW, it'd be possible to return "a bunch of values" or "nothing" by using a table? return type. However, I'm trying very hard not to allocate tables in my hot game's hot paths, thus I favor concrete types and multiple return.
- Lingua principale
- Lua
- Stelle
- 4.4k
- Fork
- 442
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di LuaLS/lua-language-server
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
LuaLS/lua-language-server#1776 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
LuaLS/lua-language-server#3461 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
LuaLS/lua-language-server#3460 · 1 commento · 1 reazione ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
LuaLS/lua-language-server#3459 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 64/100
LuaLS/lua-language-server#3458 ·
Tutte le issue di LuaLS/lua-language-server
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
api7/lua-resty-saml#62 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 94/100
codymikol/multiverse.nvim#320 ·
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100