[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: require vs dofile (lua 5.1.4 windows)
- From: Jonathan Castello <twisolar@...>
- Date: Thu, 24 Jun 2010 20:00:41 -0700
2010/6/24 Fernando P. García <email@example.com>:
> Let me add a question, which one is better according to the use case?
> better: faster, less memory footprint, vs. better: more convenient, less
> prone to errors.
If you know exactly where the file is, it's part of your code (as
opposed to an external library you're using), and if you're okay with
being able to run the file multiple times, dofile() might be the
better choice. If you're using an external library, you'll probably
want require(), with the added feature that it caches the return value
of the module so every subsequent require() won't spend extra time
running the same file (which would often be a bad idea anyways).
Keep in mind, you can also edit your own paths into package.path and
package.cpath to meet your needs.