home | roadmap | issues | ©2022,2023 by tim menzies |
script.lua : an example script with help text and a test suite
(c)2022, Tim Menzies <timm@ieee.org>, BSD-2
USAGE: script.lua [OPTIONS] [-g ACTION]
OPTIONS:
-d --dump on crash, dump stack = false
-g --go start-up action = data
-h --help show help = false
-s --seed random number seed = 937162211
ACTIONS:
-g the show settings
-g rand generate, reset, regenerate same
-g sym check syms
-g num check nums
- obj(s:str) ⇒ t
-
create a klass and a constructor
Summarize a stream of symbols.
- SYM.new(i) ⇒ SYM
-
constructor
- SYM.add(i, x) ⇒ nil
-
update counts of things seen so far
- SYM.mid(i, x) ⇒ n
-
return the mode
- SYM.div(i, x) ⇒ n
-
return the entropy
Summarizes a stream of numbers.
- NUM.new(i) ⇒ NUM
-
constructor;
- NUM.add(i, n:num) ⇒ NUM
-
add
n
, update lo,hi and stuff needed for standard deviation - NUM.mid(i, x) ⇒ n
-
return mean
- NUM.div(i, x) ⇒ n
-
return standard deviation using Welford's algorithm http://t.ly/nn_W
- rint(lo, hi) ⇒ n
-
a integer lo..hi-1
- rand(lo, hi) ⇒ n
-
a float "x" lo<=x < x
Note the following conventions for map
.
- If a nil first argument is returned, that means :skip this result"
- If a nil second argument is returned, that means place the result as position size+1 in output.
- Else, the second argument is the key where we store function output.
- map(t:tab, fun:fun) ⇒ t
-
map a function
fun
(v) over list (skip nil results) - kap(t:tab, fun:fun) ⇒ t
-
map function
fun
(k,v) over list (skip nil results) - sort(t:tab, fun:fun) ⇒ t
-
return
t
, sorted byfun
(default=<
) - keys(t:tab) ⇒ ss
-
return list of table keys, sorted
- fmt(sControl:str, ...) ⇒ str
-
emulate printf
- oo(t:tab) ⇒ t
-
print
t
then return it - o(t:tab, isKeys:{bool}) ⇒ s
-
convert
t
to a string. sort named keys. - coerce(s:str) ⇒ any
-
return int or float or bool or string from
s
- settings(s:str) ⇒ t
-
parse help string to extract a table of options
- cli(options:tab) ⇒ t
-
update key,vals in
t
from command-line flags
main
fills in the settings, updates them from the command line, runs
the start up actions (and before each run, it resets the random number seed and settongs);
and, finally, returns the number of test crashed to the operating system.
- main(options:tab, help, funs:{fun}) ⇒ nil
-
main program