version is just defined as a list at the top of nomsu.moon, and uses X.Y.Z form instead of X.Y.Z.W. Added a ([...], from 2) method and a ([...], up to 5) method, and fixed a few upgrade bugs.
98 lines
2.9 KiB
Plaintext
Executable File
98 lines
2.9 KiB
Plaintext
Executable File
#!/usr/bin/env nomsu -V6.15.13.8
|
|
#
|
|
This file defines a Read-Evaluate-Print-Loop (REPL) for Nomsu
|
|
|
|
use "consolecolor"
|
|
use "filesystem"
|
|
use "commandline"
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
external:
|
|
(help) means:
|
|
say ("
|
|
This is the Nomsu v\($(NOMSU VERSION), joined with ".") interactive console.
|
|
You can type in Nomsu code here and hit 'enter' twice to run it.
|
|
To exit, type 'exit' or 'quit' and hit enter twice.
|
|
")
|
|
|
|
(tutorial) means:
|
|
(use "tools/tutorial").run_with {.extras = []}
|
|
exit
|
|
|
|
command line program with $args:
|
|
say ("
|
|
|
|
\(bright)\(underscore)Welcome to the Nomsu v\($(NOMSU VERSION), joined with ".") interactive console!\
|
|
..\(reset color)
|
|
press 'enter' twice to run a command
|
|
type 'tutorial' to run the tutorial
|
|
|
|
")
|
|
|
|
# Best way I know of to detect the number of return values and only
|
|
print if it's >0:
|
|
(say results of (*extra arguments*)) means:
|
|
$N = (select "#" (*extra arguments*))
|
|
if ($N == 0):
|
|
return
|
|
for $ in 1 to $N:
|
|
$ret = (select $ (*extra arguments*))
|
|
if ($ret is "Text"):
|
|
$ret = (quote $ret)
|
|
say "\$ret"
|
|
|
|
repeat:
|
|
say (bright (yellow ">> ")) inline
|
|
$buff = []
|
|
repeat:
|
|
say (bright) inline
|
|
$line = ($io.read "*L")
|
|
say (reset color) inline
|
|
if (($line == "\n") or (not $line)):
|
|
if ((size of $buff) > 0):
|
|
# clear the line
|
|
if $(COLOR ENABLED):
|
|
say "\027[1A\027[2K" inline
|
|
go to (run buffer)
|
|
$buff, add ($line, with "\t" -> " ")
|
|
say (dim (yellow ".. ")) inline
|
|
--- (run buffer) ---
|
|
if ((size of $buff) == 0): stop
|
|
$buff = ($buff, joined)
|
|
spoof file $buff
|
|
try:
|
|
$tree = ($buff parsed)
|
|
..if it fails with $err:
|
|
say $err
|
|
do next
|
|
|
|
unless $tree:
|
|
do next
|
|
|
|
if ($tree.type == "Comment"):
|
|
say (dim "Comment:\($tree.1)")
|
|
do next
|
|
|
|
if ($tree.type != "FileChunks"):
|
|
$tree = [$tree]
|
|
|
|
for $chunk in $tree:
|
|
try:
|
|
$lua = ($chunk as lua)
|
|
..if it fails with $err: say $err
|
|
|
|
unless $lua:
|
|
do next
|
|
|
|
# TODO: this is a bit hacky, it just defaults variables to global
|
|
so that stuff mostly works across multiple lines. It would be
|
|
nicer if local variables actually worked.
|
|
$lua, remove free vars
|
|
if (load "return \($lua, text)"):
|
|
$lua, prepend "return "
|
|
|
|
try:
|
|
say results of (run $lua)
|
|
..if it fails with $err: say $err
|