question about wait.lua-Why the addtimer's sending script has no argument

Posted by Wayen on Fri 14 Oct 2016 04:09 PM — 3 posts, 14,425 views.

China #0
I researched this code and find a question that is the addtimer's sending script-wait.timer_resume has no argument,but the function definition has argument like this:
function timer_resume (name)

if the timer trigger the script(wait.timer_resume),How could the function(timer_resume) recongnize the argument and find the thread which stored in table(threads)?

-------------------------------------------------------------

function timer_resume (name)
  local thread = threads [name]
  if thread then
    threads [name] = nil
    local ok, err = coroutine.resume (thread)
    if not ok then
       ColourNote ("deeppink", "black", "Error raised in timer function (in wait module).")
       ColourNote ("darkorange", "black", debug.traceback (thread))
       error (err)
    end -- if
  end -- if
end -- function timer_resume 


function time (seconds)
  local id = "wait_timer_" .. GetUniqueNumber ()
  threads [id] = assert (coroutine.running (), "Must be in coroutine")

  local hours, minutes, seconds = convert_seconds (seconds)

  check (AddTimer (id, hours, minutes, seconds, "",
                  bit.bor (timer_flag.Enabled,
                           timer_flag.OneShot,
                           timer_flag.Temporary,
                           timer_flag.ActiveWhenClosed,
                           timer_flag.Replace), 
                   "wait.timer_resume"))

  return coroutine.yield ()
end -- function time
Amended on Fri 14 Oct 2016 10:04 PM by Nick Gammon
Australia Forum Administrator #1
The argument to AddTimer is "wait.timer_resume".

That is a string, not a function call. It tells the timer code what function to call when the timer fires. Built into the code that calls that function is the knowledge that it adds the timer name (which is stored in the timers table).





Similarly, in a trigger, you can supply the name of a function to call when the trigger fires. The code that does that adds four arguments: name, line, wildcards, styles
China #2
Ok,I see now.The AddTimer call function(wait.timer_resume) that will add argument(Timer'id) to the function.