lua-users home
lua-l archive

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


>> guess what I'm asking for is how do I do the reverse (remove the
>> reference by the pointer's value).

>This is a very common phenomenon.  The solution is to not store the
>pointers directly into the Lua userdata.  Instead you keep an
>in-between administration that maps "handles" --used at the lua side--
>to the actual c++ pointers and vice versa.  Handles could be just
>numbers (*).  Then whenever lua invokes an operation on such a handle,
>you check it for validity first on the c++ side.

I vaguely think I see how to do this, I've seen an example how to use the __index (IIRC, I can't find it now though) to lookup members of tables. Is this what you mean? Would this always work even for windows created inside functions as local and/or for windows put into to tables (t = {}; t.a = wx.wxPanel(...)). I would really appreciate an example if you have some time.

I'm also not sure how this would mix with the rest of the user data which which works well enough as is, (regular gdi stuff like pens, brushes, etc). Would it make sense to convert it all?

I was hoping I'd overlooked a way to just rip out lua's reference to the variable. I can get notified when wxWindows is about to delete a window, so at that point I have a valid pointer to it. If I could just completely remove lua's reference to it (back to nil as if it never existed) it would be perfect. I'd rather lua error out than a segfault.

Thanks,
-John Labenski