lua-users home
lua-l archive

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


The new "require('file')" is cool.  It tracks already-loaded files
and avoids a re-load, so that one can use require calls everywhere.

For example, with these files:

  file "ah":
    print "ah"

  file "ha":
    require "ah"
    print "ha"

The following happens:
  % lua ah
  ah
  % lua ha
  ah
  ha
  % lua ha ha
  ah
  ha
  ha
  %

However, normal loading does not mark the file as loaded:
  % lua ah ha
  ah
  ah    <- this is a bit of a surprise
  ha
  % luac -o aha ah ha
  % lua aha
  ah
  ah    <- so is this
  ha
  $

Maybe it is preferable to make "dofile" also mark the file as loaded?

This has the benefit that a main script called "m", calling three
other scripts "a", "b", and "c", can then be compiled as follows:
  % luac -o m.out a b c m

If "m" contains:
  require "a"; require "b"; require "c"
  <do something useful>
then "lua m" and "lua m.out" would do the same thing.

Another question: why was "require" coded in C, and not in Lua?


-jcw