Lua Examples

LuaOct 23, 2026

Lua base64 encode and validating decode

Encodes text to base64 and decodes it back again with malformed-input checks.

decodingencodingbase64
000
LuaOct 23, 2026

Lua aligned plain-text table renderer

Formats headers and rows into aligned plain-text columns with a dashed separator line.

formattingtablesterminal
000
LuaOct 23, 2026

Lua field-level input validation with rules

Checks fields against rule functions and returns either cleaned input or per-field errors.

errorsvalidationforms
000
LuaOct 23, 2026

Lua query string encoder and parser

Encodes Lua tables into query strings and parses query strings back into decoded tables.

query-stringurlencoding
000
LuaOct 23, 2026

Lua coroutine worker pool with error capture

Runs jobs across a fixed set of cooperative coroutine workers and collects results and errors.

concurrencycoroutinesworker-pool
000
LuaOct 23, 2026

Lua JSON decoder error reporter with line/col

Wraps any JSON decoder and turns failures into line and column errors with nearby context.

decodingerrorsjson
000
LuaOct 23, 2026

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.

curlhttpjson
000
LuaOct 23, 2026

Lua env config loader with typed defaults

Reads environment variables with defaults, converts numeric values, and fails on missing keys.

environmentconfigvalidation
000
LuaOct 23, 2026

Lua token bucket with burst allowance

Refills tokens at a steady rate and allows a burst up to the bucket capacity before denying.

token-bucketrate-limitingtime
000
LuaOct 23, 2026

Lua bounded LRU cache with recency eviction

Keeps at most N entries in a table, evicting the least recently used key when inserting.

tableslrucache
000
LuaOct 23, 2026

Lua stable multi-key sorter with nil last

Sorts records by several keys, keeps equal rows stable, and places nil values last.

tablessortingcomparators
000
LuaOct 23, 2026

Lua chunk iterator for fixed-size batches

Wraps a sequence in an iterator that yields fixed-size array batches until the sequence ends.

sequencesbatchesiterators
000
LuaOct 23, 2026

Lua streaming line reader for text files

Returns an iterator that streams a text file line by line and closes the handle when exhausted.

streamingfile-ioiterators
000
LuaOct 23, 2026

Lua table deep clone and recursive merge

Recursively copies nested Lua tables and merges an override table into a deep-cloned base.

mergetablesdeep-copy
000
LuaOct 23, 2026

Lua retry with jittered exponential backoff

Retries a function with capped exponential backoff and random jitter, re-raising the last error.

backoffretryjitter
000