Page 1 of 1

Why does the luasocket sample code not work with Love2d 11.3?

Posted: Wed Apr 28, 2021 5:02 pm
by another-tech-guy24
I am trying to run the following code using love2d 11.3 on Mac OS Catalina 10.15:

https://github.com/diegonehab/luasocket ... listen.lua

code:
local socket = require"socket"
local group = "225.0.0.37"
local port = 12345
local c = assert(socket.udp())
print(assert(c:setoption("reuseport", true)))
print(assert(c:setsockname("*", port)))
print(assert(c:setoption("ip-add-membership", {multiaddr = group, interface = "*"})))
while 1 do
print(c:receivefrom())
end
But I get this error when I run it using love2d:
╰$ /Applications/love.app/Contents/MacOS/love .
Error: main.lua:5: setsockopt failed
stack traceback:
[string "boot.lua"]:777: in function <[string "boot.lua"]:773>
[C]: in function 'assert'
main.lua:5: in main chunk
[C]: in function 'require'
[string "boot.lua"]:570: in function <[string "boot.lua"]:380>
[C]: in function 'xpcall'
[string "boot.lua"]:787: in function <[string "boot.lua"]:780>
[C]: in function 'xpcall'
If I run it using lua, then it works fine. I have luasocket 3.0rc1-2 installed locally.

Is love2d 11.3 using a different variation of luasockets? I thought it was 3.0rc1.

Re: Why does the luasocket sample code not work with Love2d 11.3?

Posted: Wed Apr 28, 2021 7:47 pm
by tomxp411
I just tried this code using both the basic Lua 5.1.5 install and Love 2d. Both fail.

I get unsupported option `reuseport'

So I dug into the C source code for Luasocket...the parameter in question is defined as a p_opt pointer, which points to a t_opt structure in the opt_meth_setoption() function. (options.c line 31)

Those structures are filled out in udp.c, lines 73 and 95.

The error implies that the "reuseport" function is not present in the options parameter list, yet looking at the optset[] and optget[] definitions, it's definitely there, in both the Love2d and Lovesocket code.

However, if you compare the opt_meth_setoption function in Luasocket with the one in Love2d, there are some trivial differences... but it's enough to make it clear that the version in the Love2d library is not the same as the most current code in the Luasocket library.

** update: there was a fix to udp.c on Jun 11, 2015, that adds the socket options to getoption()...
** update 2: I just built LOVE from source... still fails in the same way.

I'm out of time right now, so I can't keep troubleshooting this. Later, I'll try overlaying the latest Luascoket code on the Love source and see if it compiles.


(still looking at the source... may edit here with updates...)

Re: Why does the luasocket sample code not work with Love2d 11.3?

Posted: Thu Apr 29, 2021 1:47 am
by slime
tomxp411 wrote: Wed Apr 28, 2021 7:47 pmthe version in the Love2d library is not the same as the most current code in the Luasocket library.
That is correct - love 11 has luasocket's source code from July 2016. There hasn't been any new release of luasocket since rc1, but there have been a bunch of commits to its soure code repository.

Re: Why does the luasocket sample code not work with Love2d 11.3?

Posted: Thu May 13, 2021 6:20 am
by another-tech-guy24
slime wrote: Thu Apr 29, 2021 1:47 am
tomxp411 wrote: Wed Apr 28, 2021 7:47 pmthe version in the Love2d library is not the same as the most current code in the Luasocket library.
That is correct - love 11 has luasocket's source code from July 2016. There hasn't been any new release of luasocket since rc1, but there have been a bunch of commits to its soure code repository.
I tried building love2d using the latest code from the luasocket library, but I still see the same issue. Do you know why that would not work?

Re: Why does the luasocket sample code not work with Love2d 11.3?

Posted: Thu May 13, 2021 6:23 am
by another-tech-guy24
tomxp411 wrote: Wed Apr 28, 2021 7:47 pm
** update: there was a fix to udp.c on Jun 11, 2015, that adds the socket options to getoption()...
** update 2: I just built LOVE from source... still fails in the same way.
Thanks for replying! I tried building love2d using the latest code from the luasocket library (which I think you did as well in your update #2?) I still see the same issue. That's so weird

Re: Why does the luasocket sample code not work with Love2d 11.3?

Posted: Thu May 13, 2021 6:35 pm
by tomxp411
Yeah, I'd have to sit down with a C++ debugger and see where the code is actually going. Going through the flow in my head, it certainly seems like it should work, but it wouldn't be the first time I've seen a program do something not entirely obvious when actually executing on silicon, rather than gray matter.