Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ Lua ➜ about calling function

about calling function

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


Posted by Sylnbb   (4 posts)  Bio
Date Thu 03 Dec 2009 07:21 PM (UTC)
Message
for example,

require "wait"
require "check"

the function 'time' in the wait.lua is called whith 'wait.time()' in lua script.
but
the function 'check' in the check.lua is called with
'check()' in lua script.

why do the two functions be called in different way?

I am new to lua and mc,
Help would be appreciated. Thanks!
Top

Posted by WillFa   USA  (525 posts)  Bio
Date Reply #1 on Thu 03 Dec 2009 08:26 PM (UTC)
Message
wait is a module. It has subcomponents to it that are stored in a table. There's wait.make, wait.time, etc. Look up "module" in the Programming in Lua book (http://www.lua.org/PiL)

check is just a snippet of code that defines a function. The function gets returned to the Global namespace (_G). You don't need to use require to get it to work. dofile() would work just as well.
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #2 on Thu 03 Dec 2009 10:15 PM (UTC)
Message
To be fair, there's also no reason you couldn't dofile() a module. require() is just a bulked-up dofile() with a search path, and caching of the return value from each file (generally a table) into package.loaded. module() just happens to set the package.loaded entry itself, so require() notices and says "Oh, nevermind."

(I might be slightly wrong on the mechanics in that last sentence, but I'm fairly certain the rest is right.)

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Sylnbb   (4 posts)  Bio
Date Reply #3 on Fri 04 Dec 2009 08:45 PM (UTC)
Message
I've got it,
and thank very much for you both!
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #4 on Fri 04 Dec 2009 10:13 PM (UTC)
Message
BTW, the "check" function is now built into MUSHclient script space. You don't need to require it at all.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


18,331 views.

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

Go to topic:           Search the forum


[Go to top] top

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