Description
Is your feature request related to a problem? Please describe:
I would like to be able to sort a list of hashes, which is currently not possible because a hash is userdata and is not comparable.
A workaround I now use is:
local player_list = { hash("p1234"), hash("p2345") }
table.sort(player_list, function(a, b)
return hash_to_hex(a) < hash_to_hex(b)
end)
Describe the solution you'd like:
I would love if a hashes are comparable (e.g. hash1 < hash2
) so table.sort just works like this:
local player_list = { hash("p1234"), hash("p2345") }
table.sort(player_list)
Describe alternatives you've considered:
Currently I use the hash_to_hex builtin to make them strings and compare these. It works, but it's a very inefficient way of sorting a list of uints..
Sorting them before hashing is also not possible in my usecase.
Additional context:
This is important for us because of multiplayer synchronization. In this example I keep track of a list of player uids, and want them sorted for leader election (the first in the list is leader if the leader leaves).
In my p2p game I also often use player0 < player1
to determine which player will be polite in case of a race condition.
Activity