Given that these user data are number-like and cannot hold references
to other objects, I think one approach might be to use reference
counting. Also at least within expressions, and for objects created
and used only in a single scope, it might be relatively easy to
determine their lifetime using static analysis.
It looks like LuaRC/LuaPlus [3, 4] reference counting system might be
one possible approach. Does that seem like a good fit for what I've
described above? Are there other options or approaches I should know
about? How have other people solved this problem? Are these issues
being considered at all for main-line Lua development or are they
considered out of scope?
[3] Subject: Re: Reference counting patch for Lua 5.1?
http://lua-users.org/lists/lua-l/2007-04/msg00278.html