bjorn/manaserv — comment on commit d76c84580b931560502ae414991184d41d178b4e
File:  line 0
By bjorn:

Indeed this cache should make sure that existing userdata values are reused when still available. There are two reasons for doing this:

* Performance, though this is probably pretty much irrelevant. Creating a user data object requires allocating memory on the heap, which is relatively slow compared to using a light user data (a light user data is equivalent to passing an integer around).

* Equivalence. This is the somewhat more important reason. A user data object is only equal to itself. In particular, two user data objects that point to the same object will not compare as equal. This cache makes sure that this won't happen, since when there still is an existing user data referencing the same object, it will be reused.

I guess I shall mention these points in the class documentation.

I'm not sure what you mean by reducing the number of different stacks. I want to reduce the number of different Lua states, but this is change is unrelated to that.

As for being comfortable with Lua metatables and registry... it took me a while to get it right. :-)