abstract userdata behind C++ templates

In the util.hxx header, some general-purpose templates are now used for
userdata, which is stored in the Lua userdata storage rather than as a
pointer to stack space.