Usage of socket in widgets

Usage of socket in widgets

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
Aneque
Posts: 3
Joined: 05 Apr 2013, 21:10

Usage of socket in widgets

Post by Aneque »

Hello!
Could you help me, please?
I cann't use socket with widgets. I tried to start example widget, which uses socket (\Spring\engine\91.0\examples\Widgets\luasocket.lua):

Error: Error in Initialize(): [string "LuaUI\Widgets\luasocket.lua"]:64: attempt to index upvalue 'socket' (a nil value)

line 64: client=socket.tcp()

before socket was defined using: local socket = socket

Also in system.lua present line: socket = socket,

I use spring 91.0.
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: Usage of socket in widgets

Post by Silentwings »

local socket = socket, I think, will initialize socket with nil value. What will happen is that you've tried to inialize socket as equal to itself, but socket isn't defined yet so it will be initialized to nil. If you are trying to initialize socket to have the value of a string reading 'socket', I think you should use local socket = "socket".
abma
Spring Developer
Posts: 3798
Joined: 01 Jun 2009, 00:08

Re: Usage of socket in widgets

Post by abma »

did you set LuaSocketEnabled=1 in springsettings.cfg? luasocket is disabled as default before spring 92.0.
Aneque
Posts: 3
Joined: 05 Apr 2013, 21:10

Re: Usage of socket in widgets

Post by Aneque »

Thank you very much for help, guys!
My fault, I just didn't set LuaSocketEnabled=1...
But I don't understand why this check was passed:

if not Spring.GetConfigInt("LuaSocketEnabled", 0) == 1 then
Spring.Echo("LuaSocketEnabled is disabled")
return false
end

Anyway, I added LuaSocketEnabled=1 and now I can create socket)))
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Usage of socket in widgets

Post by zwzsg »

"not" has a higher priority than "=="
So when you write: if not a==b then
You think you write: if not (a==b) then
But what you actually write is: if (not a) == b then
It caught me many times as well.
I suggest you use ~=
abma
Spring Developer
Posts: 3798
Joined: 01 Jun 2009, 00:08

Re: Usage of socket in widgets

Post by abma »

Aneque
Posts: 3
Joined: 05 Apr 2013, 21:10

Re: Usage of socket in widgets

Post by Aneque »

zwzsg, good to know, thanks)
abma, nice!)
Post Reply

Return to “Lua Scripts”