lua-users home
lua-l archive

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


On Saturday 03 September 2005 00.19, DC wrote:
> Is it possible for the c/c++ side to 'revoke' a userdata from a
> script?

I don't think there is a safe way of doing that. I think this applies 
to any language; not just Lua: If you've acquired some resource, you 
don't expect it to just disappear all of a sudden. You either release 
it explicitly, or implicitly via some form of automatic memory 
management.


>   For example, an object which exists in one level of a game, but is
> no longer used or valid in the next level?  If the script forgets to
> release the object it could persist.

Well, if the script "forgets" to release an object, it means it's 
holding on to stuff that should no longer be around. I'd me more 
worried about what's wrong with the script, than the relatively 
harmless memory leak, which is just a side effect.


> One solution has been to destroy the lua state when transitioning 
> between levels.  But, I want to be able to pass and maintain state.

Rather than destroying the whole Lua state, why not clean out 
everything that isn't explicitly part of the "cross level" game 
state? If you throw away all tables and stuff that are meant to have 
single level life time, there can't be any references to the userdata 
hanging around, unless you're doing something bad in the scripts.


Of course, if all else fails, one way is to make the userdata a 
lightweight interface to the real objects, so you can destroy the 
latter while leaving the userdata around, marked "invalid."


//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
|  Free/Open Source audio engine for games and multimedia.  |
| MIDI, modular synthesis, real time effects, scripting,... |
`-----------------------------------> http://audiality.org -'
   --- http://olofson.net --- http://www.reologica.se ---