[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: What do people use globals for?
 
- From: "Peter Hill" <corwin@...>
 
- Date: Mon, 6 Jan 2003 16:07:04 -0000
 
Peter Hill:
> What situations do people tend to use globals for (as opposed to file-wide
> locals)?
Joshua Jensen:
> Why, things needing to be global, of course.  Shared data across different
> source files.  Shared functions.
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
*cheers*
Peter Hill.