lua-users home
lua-l archive

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


Peter Hill wrote:
> 
> Other source files defining globals is not very modular. I tend to take
> advantage of the (rather unique) feature of Lua "dofile" that allows return
> values.
> 
> I'd much rather load a complex number package (for example) using:
>     complex = dofile("complex.lua")
> 
> than the global version
>     dofile("complex.lua")
> 
> The file "complex.lua" has:
>   local c = {}
>   function c.add ... end
>   function c.sub ... end
>   etc
> 
>   return c


Well, it's a matter of taste, but I personally prefer
a  "complex = c" at the end of complex.lua,
so I can saydofile("complex.lua") and use complex
immediately. If I have a conflicting package, I can always
do some renaming before the "dofile()" call. 

Also, for global data, you'll need global variables.
As was mentioned elswhere. 


-- 
"No one knows true heroes, for they speak not of their greatness." -- 
Daniel Remar.
Björn De Meyer 
bjorn.demeyer@pandora.be