Generate __index and __newindex metamethods via a factory function