lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


hi there! :)

think outside of the box, it is possible, just by the other way around! :)

what u will need is something like a `table.getKeys()` and then utilizing the builtin `table.sort()` on the keys. `12` should come after `2`, and integer keys should come before other types, and either the a type order or for the same types their value will decide the order, while only integer keys should necessarily be handled specially, the rest can get string comparison. `1.2` should still belong to the hash part, this is a thing i didnt think about so far now.

going even further, u can make either a `table.getSortedKeys()` or just give a parameter for `table.getKeys()`, that is, when it is `true`, it will sort the way u wanted as a default, when it is a function, then it will be a function for sorting, or a table, that can be fed into that default function as a table describing the type order, like `{number=1, string=2, ['function']=3}` (just with all types).

still, why stop here? u can even write `spairs()` with all the stuffs included from above. :)

btw u can actually find like 4-5 implementations for serialization in the wild that im aware of, so maybe even more... :D

have fun! :)

Sent with ProtonMail Secure Email.