Some general LUA functions. (c)2022 Tim Menzies [email protected] BSD-2 license
For examples on how to use this code, see https://tinyurl.com/gluaeg.
| What | Notes |
|---|---|
| l.rogues() ⇒ nil | report rogue locals |
| What | Notes |
|---|---|
| l.same(x, ...) ⇒ x | return x unmodified |
l.sd(ns:(num)+, fun:fun) ⇒ num |
return standard deviation |
The LUA doco says its random number generator is not stable across platforms. Hence, we use our own (using Park-Miller).
| What | Notes |
|---|---|
l.srand(n:num) ⇒ nil |
reset random number seed (defaults to 937162211) |
l.rand(nlo:num, nhi:num) ⇒ num |
return float from nlo..nhi (default 0..1) |
l.rint(nlo:num, nhi:num) ⇒ int |
returns integer from nlo..nhi (default 0..1) |
| What | Notes |
|---|---|
l.any(t:tab) ⇒ any |
return any item from t, picked at random |
l.many(t:tab, n:num) ⇒ t |
return n items from t, picked at random |
l.per(t:tab, p) ⇒ num |
return the pth(=.5) item of sorted list t |
l.ent(t:tab) ⇒ num |
entropy |
l.kap(t:tab, fun:fun) ⇒ t |
map function fun(k,v) over list (skip nil results) |
l.keys(t:tab) ⇒ t |
sort+return t's keys (ignore things with leading _) |
l.map(t:tab, fun:fun) ⇒ t |
map function fun(v) over list (skip nil results) |
l.push(t:tab, x) ⇒ any |
push x to end of list; return x |
l.slice(t:tab, go, stop:str, inc) ⇒ t |
return t from go(=1) to stop(=#t), by inc(=1) |
| What | Notes |
|---|---|
l.gt(s:str) ⇒ fun |
return a function that sorts ascending on `s'. |
l.lt(s:str) ⇒ fun |
return a function that sorts descending on s. |
l.sort(t:tab, fun:fun) ⇒ t |
return t, sorted by fun (default= <) |
| What | Notes |
|---|---|
l.coerce(s:str) ⇒ any |
return int or float or bool or string from s |
l.options(s:str) ⇒ t |
parse help string to extract a table of options |
l.csv(sFilename:str, fun:fun) ⇒ nil |
call fun on rows (after coercing cell text) |
| What | Notes |
|---|---|
l.fmt(sControl:str, ...) ⇒ str |
emulate printf |
l.oo(t:tab) ⇒ nil |
print t's string (the one generated by o) |
l.o(t:tab, seen:str?) ⇒ str |
table to string (recursive) |
| What | Notes |
|---|---|
l.obj(s:str) ⇒ t |
create a klass and a constructor + print method |
Test suite support
| What | Notes |
|---|---|
l.cli(t:tab) ⇒ t |
alters contents of options in t from the command-line |
l.run(t:tab, funs:(fun)+) ⇒ nfails |
runs all funs (or t.go), resetting options & seed before each |
That's all folks.