Agreed, the real problem is without __gc on light userdata you can never be sure when Lua has released the last pointer, so it is of limited use unless the pointer is to static memory or heap memory that will not be released until after the Lua state is closed. I'm with you, I tend to wrap C pointers in full userdata so that I can track GC correctly.
--Tim In my opinion the term "light userdata" is a bit misleading, as I see only a very limited value in using it for storing actual data. You cannot assign different metatables to each light userdata. That means it is later very hard to find out what was actually stored in it. And I don't see any way of making sure that Lua has no stray pointers left -- except by closing the entire Lua state. So even when I need to do memory handling in C I would store a pointer in a full userdata.
|