[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: What do people use globals for?
- From: "Joshua Jensen" <jjensen@...>
- Date: Mon, 6 Jan 2003 01:39:42 -0700
> 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")
If you have more than one script loading the complex number package
through dofile(), then more memory is lost, because it reloads the
complex.lua script each time and each "complex" variable gets its own
copy of everything, including code, line information, etc.
Of course, this could be remedied with some form of package management
system, but I was just commenting on your example.
I use Lua a lot for data. I find Lua to be a much better data providing
system than, say, XML. Oftentimes, my data builds on one another. For
instance, let's say I was creating a game with monsters. I only want to
load the monsters used in the level.
Monsters = {}
CrabbyMonster.lua:
Monsters.CrabbyMonster = { data goes here }
SullyMonster.lua:
Monsters.SullyMonster = { data goes here }
(No, I'm not doing a Monsters, Inc. game, but it would be fun...)
The data inserts itself automatically into my Monsters table. No
additional effort on my part is needed.
For the most part, Lua does everything I need. I have no issue with it
providing both the ability to do functional scripting and OOP scripting.
An automatic inheritance mechanism would be nice for OOP stuff (built
into the parser and automatically filling in the appropriate __metatable
entry), but I can live with what is there.
Josh