Lua Examples
Lua base64 encode and validating decode
Encodes text to base64 and decodes it back again with malformed-input checks.
Lua aligned plain-text table renderer
Formats headers and rows into aligned plain-text columns with a dashed separator line.
Lua field-level input validation with rules
Checks fields against rule functions and returns either cleaned input or per-field errors.
Lua query string encoder and parser
Encodes Lua tables into query strings and parses query strings back into decoded tables.
Lua coroutine worker pool with error capture
Runs jobs across a fixed set of cooperative coroutine workers and collects results and errors.
Lua JSON decoder error reporter with line/col
Wraps any JSON decoder and turns failures into line and column errors with nearby context.
Lua curl-backed JSON GET with hard timeout
Uses curl through io.popen to GET JSON with a hard timeout and a caller-supplied decoder.
Lua env config loader with typed defaults
Reads environment variables with defaults, converts numeric values, and fails on missing keys.
Lua token bucket with burst allowance
Refills tokens at a steady rate and allows a burst up to the bucket capacity before denying.
Lua bounded LRU cache with recency eviction
Keeps at most N entries in a table, evicting the least recently used key when inserting.
Lua stable multi-key sorter with nil last
Sorts records by several keys, keeps equal rows stable, and places nil values last.
Lua chunk iterator for fixed-size batches
Wraps a sequence in an iterator that yields fixed-size array batches until the sequence ends.
Lua streaming line reader for text files
Returns an iterator that streams a text file line by line and closes the handle when exhausted.
Lua table deep clone and recursive merge
Recursively copies nested Lua tables and merges an override table into a deep-cloned base.
Lua retry with jittered exponential backoff
Retries a function with capped exponential backoff and random jitter, re-raising the last error.