Module sort

This module contains a collection of comparison functions (or factories for comparison functions) for table.sort.

Functions

natsort_cmp (cache) Generates a natural sorting comparison function for table.sort.


Functions

natsort_cmp (cache)
Generates a natural sorting comparison function for table.sort.

Parameters:

  • cache Optional, hashmap used to cache the processed strings to speed up sorting

Returns:

  1. The cmp function to feed to table.sort
  2. The cache used (same object as the passed one, if any; will be created if not)

Usage:

    -- t is an array of strings, we don't want to keep the cache around
    table.sort(t, sort.natsort_cmp())
    
    -- t is an array of arrays, we want to sort the strings in the "text" field of the inner arrays, and we want to keep the cache around.
    local cmp, cache
    cmp, cache = sort.natsort_cmp(cache)
    table.sort(t, function(a, b) return cmp(a.text, b.text) end)
generated by LDoc 1.5.0 Last updated 2024-03-18 16:45:36