lua-users home
lua-l archive

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


I had a similar problem for my application's GUI system, so here's what
I did:

1) I store each userdatum wrapping a widget in a registry table, keyed
by light userdatum.  This means that if a widget is wrapped by a Lua
userdatum, all references on the Lua side are through that a single
userdatum.

2) The GUI system I use allows me to listen for a widget's
destruction, so I install an event handler that cleans up the registry
table, and sets the metatable on the invalidated userdatum so all field
reads/writes fail.

-Rob

On Mon, 8 Jun 2009 19:16:42 +0000 (UTC)
Dmitry Maluka <dmitrymaluka@gmail.com> wrote:

> Hello!
> 
> Suppose that we have a Lua function foo() that creates a foo object,
> stores it in application's internal data structures and returns a
> light userdata pointer to it. The unfoo() function destroys that
> object and frees the corresponding data structures. After that, all
> the light userdata references to it are broken and may crash the
> application.
> 
> Any approaches to this problem?
> 

Attachment: signature.asc
Description: PGP signature