[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  question about wait.lua-Why the addtimer's sending script has no argument
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

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

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Wayen   China  (17 posts)  [Biography] bio
Date Fri 14 Oct 2016 04:09 PM (UTC)

Amended on Fri 14 Oct 2016 10:04 PM (UTC) by Nick Gammon

Message
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
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Fri 14 Oct 2016 10:08 PM (UTC)
Message
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

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Wayen   China  (17 posts)  [Biography] bio
Date Reply #2 on Sat 15 Oct 2016 11:02 AM (UTC)
Message
Ok,I see now.The AddTimer call function(wait.timer_resume) that will add argument(Timer'id) to the function.
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


1,649 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]