In a long time ago, after NaN tricks are removed from the Lua source, I remember Cloud Wu has a very incredible idea about the unused bits of variables.
In short, we use 8bytes for Value (because the 64bit integer and 64bit double), but use 16bits for TValue (because of the extra tt_ type information). beside the 8bit for tt_, we have 56bit unused in TValue.
We can use these space for a "ref" value of a table in the registry, that's the metatable of the variable, this value will be tracked with the variable. They move with the moving of the variable.
In this case, we can introduce separate metatable for even every integer, boolean, function, etc. we can track the behavior of the variable, such as to-be-closed. because the metatable is binding to the variable, but not the value, we could simply make a function to assign a variable metatable to contain the __close metamethod. we could use metatable to declare the variable is constant and to form the behavior when the variable joins the calculates.
Maybe we could call this "variable metatable" to "metadata", so use new functions for that:
void lua_setmetadata(lua_State *L, int idx, int ref);
int lua_getmetadata(lua_State *L, int idx);
to get the table, just dereference the ref with lua_rawgeti(L, LUA_TREGISTRYINDEX, ref).
But it's still a big change for Lua 5.3.x, so now we are ready for 5.4, may this feature contains in 5.4 or is there still any difficult of this idea?