Nomsu v7.0.0 API
The Nomsu API.
This page has a listing of the Nomsu API, automatically generated using this script. Click on an action’s name to see its definition and a link to where it’s defined in the codebase. This API documentation does not include complete descriptions of what each action does, but hopefully the actions are descriptively-enough named, and have readable-enough source code that it will be easy to understand what they do.
Nomsu v7.0.1 API
lib/base64/init.nom
-
base64 $str[base64 $str, base64 encode $str, $str base64] all mean: $chars = [] for $i in (1 to #$str by 3): $bytes = [=lua "\$str:byte(\$i, \($i + 2))"] $chars, add $b64_chars.((($bytes.1 & 252) >> 2) + 1) if #$bytes is: 3: $chars, add $b64_chars.((($bytes.1 & 3) << 4) + (($bytes.2 & 240) >> 4) + 1) $chars, add $b64_chars.((($bytes.2 & 15) << 2) + (($bytes.3 & 192) >> 6) + 1) $chars, add $b64_chars.(($bytes.3 & 63) + 1) 2: $chars, add $b64_chars.((($bytes.1 & 3) << 4) + (($bytes.2 & 240) >> 4) + 1) $chars, add $b64_chars.((($bytes.2 & 15) << 2) + 1) $chars, add "=" 1: $chars, add $b64_chars.((($bytes.1 & 3) << 4) + 1) $chars, add "=" $chars, add "=" return ($chars, joined) -
base64 encode $str[base64 $str, base64 encode $str, $str base64] all mean: $chars = [] for $i in (1 to #$str by 3): $bytes = [=lua "\$str:byte(\$i, \($i + 2))"] $chars, add $b64_chars.((($bytes.1 & 252) >> 2) + 1) if #$bytes is: 3: $chars, add $b64_chars.((($bytes.1 & 3) << 4) + (($bytes.2 & 240) >> 4) + 1) $chars, add $b64_chars.((($bytes.2 & 15) << 2) + (($bytes.3 & 192) >> 6) + 1) $chars, add $b64_chars.(($bytes.3 & 63) + 1) 2: $chars, add $b64_chars.((($bytes.1 & 3) << 4) + (($bytes.2 & 240) >> 4) + 1) $chars, add $b64_chars.((($bytes.2 & 15) << 2) + 1) $chars, add "=" 1: $chars, add $b64_chars.((($bytes.1 & 3) << 4) + 1) $chars, add "=" $chars, add "=" return ($chars, joined) -
$str base64[base64 $str, base64 encode $str, $str base64] all mean: $chars = [] for $i in (1 to #$str by 3): $bytes = [=lua "\$str:byte(\$i, \($i + 2))"] $chars, add $b64_chars.((($bytes.1 & 252) >> 2) + 1) if #$bytes is: 3: $chars, add $b64_chars.((($bytes.1 & 3) << 4) + (($bytes.2 & 240) >> 4) + 1) $chars, add $b64_chars.((($bytes.2 & 15) << 2) + (($bytes.3 & 192) >> 6) + 1) $chars, add $b64_chars.(($bytes.3 & 63) + 1) 2: $chars, add $b64_chars.((($bytes.1 & 3) << 4) + (($bytes.2 & 240) >> 4) + 1) $chars, add $b64_chars.((($bytes.2 & 15) << 2) + 1) $chars, add "=" 1: $chars, add $b64_chars.((($bytes.1 & 3) << 4) + 1) $chars, add "=" $chars, add "=" return ($chars, joined) -
chr $(chr $) means (=lua "string.char(\$)") -
decode base64 $str[decode base64 $str, $str base64 decoded, base64 decode $str] all mean: $chars = [] for $i in (1 to #$str by 4): $indices = [: for $j in ($i to ($i + 3)): add $reverse_b64.($str, character $j)] $chars, add (chr (($indices.1 << 2) + (($indices.2 & 48) >> 4))) if (($str, character ($i + 2)) == "="): stop $chars, add (chr ((($indices.2 & 15) << 4) + (($indices.3 & 60) >> 2))) if (($str, character ($i + 3)) == "="): stop $chars, add (chr ((($indices.3 & 3) << 6) + $indices.4)) return ($chars, joined) -
$str base64 decoded[decode base64 $str, $str base64 decoded, base64 decode $str] all mean: $chars = [] for $i in (1 to #$str by 4): $indices = [: for $j in ($i to ($i + 3)): add $reverse_b64.($str, character $j)] $chars, add (chr (($indices.1 << 2) + (($indices.2 & 48) >> 4))) if (($str, character ($i + 2)) == "="): stop $chars, add (chr ((($indices.2 & 15) << 4) + (($indices.3 & 60) >> 2))) if (($str, character ($i + 3)) == "="): stop $chars, add (chr ((($indices.3 & 3) << 6) + $indices.4)) return ($chars, joined) -
base64 decode $str[decode base64 $str, $str base64 decoded, base64 decode $str] all mean: $chars = [] for $i in (1 to #$str by 4): $indices = [: for $j in ($i to ($i + 3)): add $reverse_b64.($str, character $j)] $chars, add (chr (($indices.1 << 2) + (($indices.2 & 48) >> 4))) if (($str, character ($i + 2)) == "="): stop $chars, add (chr ((($indices.2 & 15) << 4) + (($indices.3 & 60) >> 2))) if (($str, character ($i + 3)) == "="): stop $chars, add (chr ((($indices.3 & 3) << 6) + $indices.4)) return ($chars, joined)
lib/commandline/init.nom
-
command line program with $args $body(command line program with $args $body) parses as: external ((run with $args) means $body) if (this file was run directly): run with (the command line arguments) -
usage $(usage $) means: say "Usage: \$" exit 1
lib/file_hash/init.nom
-
hash $(hash $) means: $hash = (=lua "\$hashlib.new('sha1'):final(\$)") return (base64 $hash) -
hash $(hash $) means: $bytes = ($, bytes) $hash = ($bytes.1 << 7) for $i in (2 to #$bytes): $hash = ((1000003 * $hash) ~ $bytes.$i) $hash = ($hash ~ #$bytes) return "\$hash" -
file with hash $hash(file with hash $hash) means: for $filename in (files for "."): $contents = (read file $filename) $file_hash = (hash $contents) if ($file_hash == $hash): return $filename -
hash of file $filename(hash of file $filename) parses as (hash (read file $filename))
lib/filesystem/init.nom
-
files for $path(files for $path) means: $files = (=lua "Files.list(\$path)") if $files: $files = (List $files) return $files -
write to file $filename $text[ write to file $filename $text, to file $filename write $text write $text to file $filename ] all mean: unless ($filename != "stdin"): fail "Cannot write to stdin" lua> (" local file = io.open(\$filename, 'w') file:write(\$text) file:close() ") -
to file $filename write $text[ write to file $filename $text, to file $filename write $text write $text to file $filename ] all mean: unless ($filename != "stdin"): fail "Cannot write to stdin" lua> (" local file = io.open(\$filename, 'w') file:write(\$text) file:close() ") -
write $text to file $filename[ write to file $filename $text, to file $filename write $text write $text to file $filename ] all mean: unless ($filename != "stdin"): fail "Cannot write to stdin" lua> (" local file = io.open(\$filename, 'w') file:write(\$text) file:close() ") -
source lines of $tree(source lines of $tree) means: $source = ($tree.source if ($tree is syntax tree) else $tree) $file = (read file $source.filename) return [: for $ in ($file, line number at $source.start) to ($file, line number at $source.stop) ..: add ($file, line $) ], joined with "\n"
lib/progressbar/init.nom
-
$x / $w progress bar($x / $w progress bar) means: $x = ($x clamped between 0 and $w) if $(COLOR ENABLED): $bits = [" ", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█"] $middle = ("" if ($x == $w) else $bits.(1 + (floor (#$bits * ($x mod 1))))) return (" \(reset color)[\(green)\($bits, last, rep (floor $x))\($middle)\ ..\(" ", rep ($w - ((floor $x) + 1)))\(reset color)] ") ..else: ### Probably not unicode support either: return "[\("#", rep ($x, rounded down))\("-", rep ($w - ($x, rounded down)))]" -
$w wide $ progress bar($w wide $ progress bar) means (($ * $w) / $w progress bar)
lib/shell/init.nom
-
at $callsite =sh $cmd(at $callsite =sh $cmd) means: $f = ($io.popen $cmd) $contents = ($f, read "*a") [$ok, $return_type, $return] = ($f, close) unless $ok: if ($return_type == "exit"): at $callsite fail "Command failure: Command `\($cmd)` failed with exit code \$return" ..else: at $callsite fail "Command failure: Command `\($cmd)` was terminated by signal \$return" return $contents -
at $callsite sh> $cmd(at $callsite sh> $cmd) means: [$ok, $return_type, $return] = ($os.execute $cmd) unless $ok: if ($return_type == "exit"): at $callsite fail "Command failure: Command `\($cmd)` failed with exit code \$return" ..else: at $callsite fail "Command failure: Command `\($cmd)` was terminated by signal \$return" -
=sh $cmd(=sh $cmd) compiles to \(at \("Text" tree with "\($cmd.source)") =sh \$cmd) -
sh> $cmd(sh> $cmd) compiles to \(at \("Text" tree with "\($cmd.source)") sh> \$cmd)
