Jump to content

sorted_pairs function in util.lua not working as expected?


Serpens
  • Closed

In util.lua you have two functions to iterate in a sorted order about key,value tables:
orderedPairs(t) (copy paste from lua website) and sorted_pairs(t,fn).
I assume that they should do the same, except sorted_pairs can handle a custom sorting function.

But currently sorted_pairs(t,fn) is not working. When you give it a table like {b=10,a=40,c=50} it should sort it by key, so alphabetically. But instead you will receive 1,2,3 as keys and a,b,c as values. Is this what it is supposed to do? I doubt it.


Steps to Reproduce

test your sorted_pairs function in util.lua and see if it does behave like expected.




User Feedback


This function is used in an internal debugger and this is how it expects the table to be sorted. The name is not the most ideal for the function as it does not explain what sorting it does by itself but it has been like this for far too long for me to change what it functionally does some mods might be using it for this functionality.

Changed Status to Closed

  • Like 2
  • Thanks 1

Share this comment


Link to comment
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
  • Create New...