Page 1 of 1

Usage of socket in widgets

Posted: 05 Apr 2013, 21:20
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.

Re: Usage of socket in widgets

Posted: 05 Apr 2013, 23:19
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".

Re: Usage of socket in widgets

Posted: 06 Apr 2013, 02:12
by abma
did you set LuaSocketEnabled=1 in springsettings.cfg? luasocket is disabled as default before spring 92.0.

Re: Usage of socket in widgets

Posted: 06 Apr 2013, 17:23
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)))

Re: Usage of socket in widgets

Posted: 06 Apr 2013, 21:37
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 ~=

Re: Usage of socket in widgets

Posted: 07 Apr 2013, 14:53
by abma

Re: Usage of socket in widgets

Posted: 08 Apr 2013, 20:46
by Aneque
zwzsg, good to know, thanks)
abma, nice!)