-
Notifications
You must be signed in to change notification settings - Fork 637
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
fix(inet): Return port as number in getsockname #392
Conversation
The documentation of getsockname() states that the port is returned as a number, which is also what the similar getpeername function does. Closes lunarmodules#391
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.
Thanks for reporting and fixing this.
The fix looks right to me, does it pass the sniff test for you @siffiejoe?
I guess my only question would be is there any circumstance where this would be a breaking change for existing usage? In most places Lua is going to cast this anyway. Is there any use case where this is going to break? Perhaps people have written conditionals like if port == "25" then
... are we going to screw them up?
If so should we make this a major release bump? Or just change the documentation to say we return a string and leave it like it is?
Also when used as parameter in |
As far as I know all supported versions of Lua will cast a number to a string when used with local port = 80
print(string.format("example.com:%s", port)) Likewise string concatenation works print("example.com:"..port) So far I haven't come up with a likely situation that would break except equality comparison return port == "80" Unfortunately that kind of test is likely to exist in the wild making this a potential breaking change. What would be the harm in changing the documentation to document that we return a string and just leaving it? |
The |
Why do you say that? $ lua5.1 -e 'port = 6; print(string.format("example.com:%s", port))'
example.com:6
Fair enough, thanks for the review. I'll probably hold of on merging this for a little bit until I sort out where we are at with other minor changes that maybe should be released before we send out a breaking one. |
My bad. I just remembered that Lua 5.1 uses |
Yes. I believe it also makes a difference for |
The documentation of getsockname() states that the port is returned as a number, which is also what the similar getpeername function does.
Closes #391