lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Fri, Jun 25, 2010 at 5:29 AM, Duncan Cross <> wrote:
> I think that require() is not intended to be used in the way you are
> trying to use it. The module name passed in is not expected to include
> details of where the module is to be found on the file system.


also, require doesn't "treat '.' as '\' "; the dot is used for package
hierarchy, so  "main.specific" means the submodule "specific" inside
the bigger package "main".  of course, it also maps to a filename of
'main/specific', but that's an implementation detail.

you don't add ".lua" to the module name, because it might be a C
module, which could use ".so", or mabye ".dll", so you leave that to
the search path.  (which is different on each platform)

dofile(), OTOH, is a simpler, lower level function. it simply means to
read and compile some Lua code.  it won't be C code, it won't be
registered in the package subsystem, it won't be searched anywhere
besides the specific path, the pathname won't be modified or inspected
before opening the file.

the intended usage of require() is to modularize your application.
require() loads modules.  either application-specific modules you
write, or generic modules you get.  (like LuaSocket, LuaSQL, etc)

the intended usage of dofile() is to either write your own
module-management system, or use it to allow the user to extend your
application.  this way you have complete control of what code to read,
and what to do with it once compiled.