-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correct description of global unpack's parameters #341
Conversation
Correct the description of the unpack parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @dv-extrarius, thanks so much for helping improve the Roblox creator documentation! Our technical writing team will review your pull request soon. In the meantime, please ensure you've read through the README.md, contribution guidelines, and style recommendations.
I reverted the suggestion of the "j" parameter, which isn't the "index of the last element to unpack", but rather the number of indices to unpack (default to the total number of indices) starting from the given index number "i" (default of the first index). |
That's not how it functioned for me in roblox. I had an array and wanted slices so I tried with i=1, 11, 21, etc and j=10 and only the first slice had elements. When I made j=10, 20, 30, etc it functioned as I wanted, slicing 10 elements at a time. In roblox, this code: local values = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
local slice1 = {unpack(values, 1, 3)}
print("Slice1 length:", #slice1)
local slice2 = {unpack(values, 4, 3)}
print("Slice2 length:", #slice2)
local slice3 = {unpack(values, 7, 3)}
print("Slice3 length:", #slice3) produces this output:
whereas this code in roblox: local values = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
local slice1 = {unpack(values, 1, 3)}
print("Slice1 length:", #slice1)
local slice2 = {unpack(values, 4, 6)}
print("Slice2 length:", #slice2)
local slice3 = {unpack(values, 7, 9)}
print("Slice3 length:", #slice3) produces
which shows j is not, in fact, a count. |
This is incorrect. Unpack takes two indices, the second argument is not the count but rather the last index. The second argument does default to the length of the input table, but this is because the last index of the table matches the length, not because the argument is a count. This is confirmed by both the Lua 5.1 and Lua 5.4 documentation as well as through empirical testing. |
I can see how the misunderstanding with the unpack function can be seen here. While yes, parameter https://github.com/luau-lang/luau/blob/e76802f2ce698ca090a793b24c07e336b21ade9f/VM/src/ltablib.cpp#L269C18-L269C18 |
Correct the description of the unpack parameters.
Changes
The description of
unpack
'sj
parameter was wrong. It is not a count, it is the index of the last element tounpack
. Updated the description of thei
parameter to match the new wording of thej
parameter.Checks
By submitting your pull request for review, you agree to the following: