Use table syntax to work with >lines<
This commit is contained in:
parent
621cef2ab5
commit
6232bf5180
26
telnet.lua
26
telnet.lua
@ -1,16 +1,18 @@
|
||||
-- Telnet client
|
||||
local telnetClient=nil
|
||||
lines = {}
|
||||
-- Telnet Server
|
||||
function startTelnetServer()
|
||||
s=net.createServer(net.TCP, 180)
|
||||
s:listen(23,function(c)
|
||||
global_c=c
|
||||
printlines = {}
|
||||
telnetClient=c
|
||||
function s_output(str)
|
||||
if(global_c~=nil) then
|
||||
if #printlines > 0 then
|
||||
printlines[ #printlines + 1] = str
|
||||
if (telnetClient ~= nil) then
|
||||
if (#lines > 0) then
|
||||
table.insert(lines, str)
|
||||
else
|
||||
printlines[ #printlines + 1] = str
|
||||
global_c:send("\r") -- Send something, so the queue is read after sending
|
||||
table.insert(lines, str)
|
||||
telnetClient:send("\r") -- Send something, so the queue is read after sending
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -20,11 +22,13 @@ function startTelnetServer()
|
||||
end)
|
||||
c:on("disconnection",function(c)
|
||||
node.output(nil)
|
||||
global_c=nil
|
||||
telnetClient=nil
|
||||
end)
|
||||
c:on("sent", function()
|
||||
if #printlines > 0 then
|
||||
global_c:send(table.remove(printlines, 1))
|
||||
if (#lines > 0) then
|
||||
local localstr = table.remove(lines, 1)
|
||||
print( tostring(localstr) )
|
||||
telnetClient:send(localstr)
|
||||
end
|
||||
end)
|
||||
print("Welcome to the Wordclock.")
|
||||
@ -32,5 +36,5 @@ function startTelnetServer()
|
||||
print("- storeConfig()")
|
||||
print("Visite https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en for further commands")
|
||||
end)
|
||||
print("Telnetserver is up")
|
||||
print("Telnetserver started")
|
||||
end
|
Loading…
Reference in New Issue
Block a user