lua-users home
lua-l archive

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


> A feature of the preprocessor I use often is taken from the current FAQ,
> section 3.6:
> 
>      $if modulename
>      $endinput
>      $end
> 
> I use this quite a bit and would like to know what the equivalent will be under 
> the next version of Lua.

For most uses, a simple «if modulename then return end» will do the job. 
Although the module will be compiled, usually the compile time is 
negligible. If you have really big modules, or modules that are re-inserted 
too many times, then you may need a more eficient solution. A redefinition
of `dofile' seems to work fine:  (I din't test it)

AlreadyLoaded = {}
dofile = function (f)
           if AlreadyLoaded[f] then return 1
           else
             AlreadyLoaded[f] = 1
             return %dofile(f)
           end
         end

-- Roberto