As the title says... Chat on...

User avatar
By alonewolfx2
#3821 node.input and node.output functions are asyn. am i right? and loadstring() function just send string to the lua? we have some information of this function. how can we send command to the lua interpreter and wait for calback?

here is working code but i am getting executed code after all code executed
Code: Select allrepeat
        local line=file.readline()
        if line then
          -- strip the \n at the end of the line
          line = string.gsub(line,"\n","")
          if line == "<?lua" then
        node.input(file.readline().."\r\n")
        function s_output(str)
        if (conn~=nil) then
        conn:send(str) end
        end
        node.output(s_output,1)
        end
          if line == "?>" then end
          conn:send(line)
        end
      until not line
User avatar
By gerardwr
#3871 I'm still trying to figure out how this works, no clue yet, read the API doc a million times, and have already spent MANY hours on this :cry:

Can someone please explain the behavior of this simple testcode and output. Every 5 secs a simple expression is executed with node.input.
Code: Select allfunction s_output(str)
  if str then
    s=str
  end -- if
end -- function


s=""
c="print(3+5)"

tmr.alarm(5000, 1, function()

     print("node.output(s_output,1)")
     node.output(s_output,1)
     node.input(c)
     node.output(nil)
     print("node.output(nil)")
     print("----")
     print(s)
     print("----")

     print("node.output(s_output,0)")
     node.output(s_output,0)
     node.input(c)
     node.output(nil)
     print("node.output(nil)")
     print("----")
     print(s)
     print("----")

end) -- tmr.alarm


Output in the console is this, and is repeated every 5 secs.

Code: Select allnode.output(s_output,1)
node.output(nil)
----

----
node.output(s_output,0)
node.output(nil)
----

----
8


My observations:
1. It seems that function s_output is never called,
2. If node.output(s_output,0) is used, the correct result 8 is printed in the console. If node.output(s_output,1) is used, the correct result 8 is NOT printed in the console. The API doc says :serial_debug: 1 output also show in serial. 0: no serial output. That's the opposite from my observations, or is it?

Who can explain the behavior of my code, I'm stuck. I don't mind being told that I made stupid mistakes in my code. Enlighten me!