lua-users home
lua-l archive

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


William Ahern <william@25thandclement.com>于2015年8月21日周五 上午9:16写道:
Yes, that sounds like a genius idea! It took me awhile to think through all
the implications. IIUC, the OP could just generate a single unique metatable
for each full userdata object he wants to clone. He stores a reference to
the full userdata object in the metatable; the lightuserdata value becomes
the index into the full userdata (or some other object it references).

At first, I like this idea :) 

If we don't care the lightuserdata's life time , we can share the unique metatable for each full userdata type .

Put a weak table into metatable to reference all the live userdata for safe. When we need access lightuserdata , check the table first to verify whether  the userdata it refer to is still alive.