You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: MultiReturn unpacking with get accessors is broken #1542
Upon running the example below, you'll quickly realize that the getter function errors, whereas the normal function does not.
Even though they consist of the same code.
The issue seems to be with unwrapping return values in class getters.
What should happen instead?
I think most of us would simply expect both these code snippets to work the exact same, aka to unwrap the return values without any issues.
changed the title [-]fix: retval unpacking in class getters are broken[/-][+]fix: MultiReturn unpacking with get accessors are broken[/+]on Mar 1, 2024
changed the title [-]fix: MultiReturn unpacking with get accessors are broken[/-][+]fix: MultiReturn unpacking with get accessors is broken[/+]on Mar 1, 2024
I'm pretty sure the syntax local c, d = table.unpack(self.Test1) can't work at all in Lua, since multiple returns can only come out of functions, and self.Test1 is a parameter, so it can only give you one value.
Here's how it'd work in pure Lua:
t=setmetatable({}, { __index=function() return1,2,3end }) -- Makes it so any property of t returns $multi(1,2,3)a, b, c=t.dummyprint(a) -- 1print(b) -- nilprint(c) -- nilprint(t.dummy) -- 1print(unpack(t.dummy)) -- Error: bad argument #1 to 'unpack' (table expected, got number)
The only solution would be to make getters actually call the function, but I think that would remove any benefit of using a getter in the first place.
Activity
[-]fix: retval unpacking in class getters are broken[/-][+]fix: MultiReturn unpacking with get accessors are broken[/+][-]fix: MultiReturn unpacking with get accessors are broken[/-][+]fix: MultiReturn unpacking with get accessors is broken[/+]Gudine commentedon Oct 24, 2024
I'm pretty sure the syntax
local c, d = table.unpack(self.Test1)can't work at all in Lua, since multiple returns can only come out of functions, andself.Test1is a parameter, so it can only give you one value.Here's how it'd work in pure Lua:
The only solution would be to make getters actually call the function, but I think that would remove any benefit of using a getter in the first place.