Skip to content

How to do multiple named return values? #3374

Closed
LuaLS/LuaLS.github.io
#109

Description

@ChillerDragon

https://luals.github.io/wiki/annotations/#return

I tried this

---@return boolean, string ok result comment
local function parse(input)
	local ok = true
	local result = "foo"
	return ok, result
end

---@return boolean, string ok, result comment
local function parse2(input)
	local ok = true
	local result = "foo"
	return ok, result
end
Image

Activity

  1. carsakiller commented on Mar 10, 2026

    @carsakiller
    Collaborator

    You should use a @return per return value:

    ---@return boolean success
    ---@return string error
    function foo() end
  2. ChillerDragon commented on Mar 11, 2026

    @ChillerDragon
    Author

    Oh I somehow thought that was for function overloading. Where it could return either one or the other.

    Will look into it 👀

  3. ChillerDragon commented on Mar 11, 2026

    @ChillerDragon
    Author

    Maybe I'll send a pr to the wiki with one more example for that. Because I feel like it's missing in the return section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat/LuaCats AnnotationsRelated to Lua Language Server Annotations (LuaCats)questionUser has a question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions