lua-users home
lua-l archive

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



   Hello all,

Let me present the background of my question:
I am  currently building a game and wish to use Lua as a means
to control characters in this game. Typical uses would be AI,
triggers (bits of code to be executed whenever specific things
happen, such as a player character talking to a non player
character, or a character walking on a particular location).
I also want to have these pieces to be modular: a 'quest' file
would hold all code/data necessary for this particular quest,
so other could be added easily (sort of plug-in stuff)

I already have a functional base for this: my characters are
controlled by a very simple Lua script and all works perfectly,
but all in a single Lua state.
My biggest concern is the following:
The more I load plug-ins, the more memory is used. And when the
player is advanced in the game, there will be lots of those. So
I thought about making a state per plug-in, and releasing part of
a plug-in when it is no more needed. The problem with this approach
is that once a character from a plug-in is loaded, it can be later
accessed even if the player entered another plug-in (the player
can go back in the maps as she wants). More, many of the memory
will be used by code (character AI behavior code), and a large
part of these behavior code will be used only before a given event
(for example a character will look for people to hire until the job
she wants the mercenaries to id is complete, and after that will
never look for people to hire again).
And (the most annoying I think) several plug-ins should be able to
exchange information.

So here is (finally) my question:
Does anyone has ideas on keeping memory usage low while keeping
data that has to be remembered handy ? Saving Lua state to disk ?
Precise garbage collecting inside a state ? Should the information
that plug-ins exchange be managed via C to allow some data to be
deleted from Lua ?
As I am very new to Lua, general indications where I could look
at would be fine too.
Any advice would be greatly appreciated.


Thanks for your time,

Vincent Penquerc'h