Multiple return values - annotating "all or nothing" #3425
Unanswered
nurpax
asked this question in
General Questions
Replies: 1 comment
-
---@type (fun(integer))|(fun(integer): integer, integer) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In my game's ECS bindings I have getter functions that work like this:
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 andreturn 0;(zero return values).This can be used in my game code like this:
Is there 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?butnumber) 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.(PS. I filed this first as an issue, but maybe it's better as a discussion.
Beta Was this translation helpful? Give feedback.
All reactions