lua-users home
lua-l archive

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


DC wrote:

Is it possible for the c/c++ side to 'revoke' a userdata from a script? 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.

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


Have a way of marking objects as no longer accessible, a generic solution is the same way files are handled in lua. Then lua just manages a handle/ptr to your data which you can set to invalid on a c side state change. Then make sure you invalidate all invalid data on state changes and check for validity before use by lua. As pointed out keeping references to old data is of course a bug, but its easier to find such bugs if you mark and catch invalid object use.


--

Kriss

http://XIXs.com -><- http://www.WetGenes.com