lua-users home
lua-l archive

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

2014-03-19 5:36 GMT+02:00  <>:

> I tried to 'require' that file, which fails with
> "/usr/bin/lua: ./scan.lua:5: module './av4msdata.lua' not found:"
> Is it possible to create an "include" for lua the clean way without
> modifying the lua installations settings like library-paths?

Differences between "require" and "dofile":

1. "dofile" wants the actual file name itself, as for
It does not apply any path search.
"require" wants the file name without extension, and
will provide .lua, .so, .dll and in fact anything you like,
depending on path settings.

2. "dofile" is done without question each time you call it.
"require" checks whether that module has already been
provided (i.e. by a previous require, by `lua -l` or by some
C function that does an API call) and if so won't do it again.

3. "dofile" can return any number of results. "require" returns
exactly one.

4. "dofile" compiles the file every time. You can instead say
av4msdata = loadfile"av4msdata.lua"
and execute av4msdata() each time. This way, you can
make "av4msdata" insert your so-called globals into a table
of your choice.