[Pre-dupsort] Fix lua distinct with nils

This is the predupsort version of https://github.com/skydb/sky/pull/144

The diff shows that there were other changes to this method in dupsort already, so this PR also brings it closer to that code.

@benbjohnson