[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]  about calling function
Home  |  Users  |  Search  |  FAQ
Register forum user name
Forgotten password?

about calling function

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

Posted by Sylnbb   (4 posts)  [Biography] bio
Date Thu 03 Dec 2009 07:21 PM (UTC)
for example,

require "wait"
require "check"

the function 'time' in the wait.lua is called whith 'wait.time()' in lua script.
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!
[Go to top] top

Posted by WillFa   USA  (525 posts)  [Biography] bio
Date Reply #1 on Thu 03 Dec 2009 08:26 PM (UTC)
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.
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #2 on Thu 03 Dec 2009 10:15 PM (UTC)
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
[Go to top] top

Posted by Sylnbb   (4 posts)  [Biography] bio
Date Reply #3 on Fri 04 Dec 2009 08:45 PM (UTC)
I've got it,
and thank very much for you both!
[Go to top] top

Posted by Nick Gammon   Australia  (21,677 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Fri 04 Dec 2009 10:13 PM (UTC)
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
[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.


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.


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]