Skip to content
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

Manually specify the number of values to unpack #185

Merged
merged 1 commit into from May 4, 2017

Conversation

SquidDev
Copy link
Contributor

@SquidDev SquidDev commented May 4, 2017

table.unpack will often stop at the first nil value, meaning some event arguments may be discarded. By storing the number of arguments through table.pack, and then using that count when unpacking, we can ensure all values are returned/resumed with.

This can be seen by running the following script:

os.queueEvent("foo", 1, nil, 2)
print(os.pullEvent("foo"))

Without this patch it will print foo 1. With it you get foo 1 nil 2 as expected. There was also an Ask a Pro issue with someone sending a nil rednet message, resulting in the protocol being nil.

Note I haven't patched any of the rom files (such as nsh) as that might be better left for their respective authors. I also haven't touched anything which deals with command line arguments - those should never be nil anyway. I'm happy to change them too, should people wish.

table.unpack will often stop at the first nil value, meaning some event
arguments may be discarded. By storing the number of arguments through
table.pack, and then using that count when unpacking, we can ensure all
values are returned/resumed with.
@dan200 dan200 merged commit 2a0556f into dan200:master May 4, 2017
@SquidDev SquidDev deleted the hotfix/unpack-length branch May 4, 2017 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants