-->
Page 1 of 2

stdin:1: attempt to index global 'senddata' (a nil value)

PostPosted: Sat Jan 17, 2015 10:24 pm
by carlhesp
Hi

I get the error when trying to dofile on a lua script which just has a function defined.
error: stdin:1: attempt to index global 'senddata' (a nil value)
What's the usual cause for this?

code works from inside the function if I copy and paste it.

Code: Select allfunction sendData()
   conn=net.createConnection(net.TCP, 0)
   conn:on("receive", function(conn, payload) print(payload) end)
   conn:connect(5050,'192.168.1.8')
   conn:send("add|"..t.read().."|ceiling\n")
   conn:close()
end

Re: stdin:1: attempt to index global 'senddata' (a nil value

PostPosted: Sun Jan 18, 2015 3:47 am
by jankop
'sendData()' is not equal 'senddata()' ! 'senddata()' is not defined.

Re: stdin:1: attempt to index global 'senddata' (a nil value

PostPosted: Sun Jan 18, 2015 6:45 am
by carlhesp
Of course! Thank you I did not notice. The problem was in init.lua triggering that function.

However now my problem is this.

my function very similar to above

Code: Select allfunction sendData()
   conn=net.createConnection(net.TCP, 0)
   conn:connect(5050,'192.168.1.8')
   conn:send("add|22.22|ceiling\n")
   conn:close()
end


when I run this function I get no TCP connection to my nodejs service. If i copy and paste that chunk of code into LuaLoader I see a TCP connection opened and the correct string come through. Any ideas on this? If i add some print lines into the function I see it output to the console when running the function.

Cheers

Re: stdin:1: attempt to index global 'senddata' (a nil value

PostPosted: Sun Jan 18, 2015 6:59 am
by ThomasW
carlhesp wrote:Of course! Thank you I did not notice. The problem was in init.lua triggering that function.

However now my problem is this.

my function very similar to above

Code: Select allfunction sendData()
   conn=net.createConnection(net.TCP, 0)
   conn:connect(5050,'192.168.1.8')
   conn:send("add|22.22|ceiling\n")
   conn:close()
end


when I run this function I get no TCP connection to my nodejs service. If i copy and paste that chunk of code into LuaLoader I see a TCP connection opened and the correct string come through. Any ideas on this? If i add some print lines into the function I see it output to the console when running the function.

Cheers

You are sending without being sure that the connection is made and closing without giving the tcp-stack a chance to actually send the data out. Move send() and close() into callbacks - here is an example:
viewtopic.php?f=24&t=1283#p7500

Thomas