0
0
This repository has been archived on 2024-05-25. You can view files and clone it, but cannot push or open issues or pull requests.
legacy-code/ideas-1.sh

196 lines
3.3 KiB
Bash

## VARIABLES ##
# $2 => $1
mov|set $1 $2
# load $1 from root scope into current scope
glob|global|pub|public $1
# vartypes:
null # null
true|false # bool
eg. -44 27 287634 # int
eg. 4.0 -3.0 0.125 # float
eg. "bla" 'blub' # str
## MATH ##
# $1 + $2 + ... => $1
add $1 $2 ...
# $1 - ($2 + ...) => $1
sub $1 $2 ...
# $1 * $2 * ... => $1
mul $1 $2 ...
# $1 / ($2 * ...) => $1
div $1 $2 ...
# $1 % $2 % ... => $1
mod $1 $2 ...
# $1 ^ $2 ^ ... => $1
pow $1 $2 ...
# root of $1 (power = $2; if not given: square-root) => $1
root $1 $2
# log of $1 (base = $2; if not given: base = 10) => $1
log $1 $2
# round to the nearest integer (.000 - .499 => round down; .500 - 0.999 => round up) => $1
round $1
# round up to the next integer => $1
ceil $1
# round down to the last integer => $1
floor $1
## CONDITIONS ##
# only execute next line if cond is true
ifl cond
# skip next line if cond is true
ifn cond
# cond:
# x
# !x
# x == y
# x != y
# x === y
# x !== y
# x < y
# x <= y
# x > y
# x >= y
## JUMPS ##
# jump to line 42 (jumping to lines inside of other scopes is not allowed)
jmp|jump|goto 42
# jump to a flag called "flag1" (flags are stored per-scope)
jmp|jump|goto "flag1"
# set flag called "flag1"
:flag1 | :flag1: | flag1:
## OUTPUT ##
# print "blabliblub"
drw|draw|echo "bla" "bli" "blub"
# initialize matrix with 16x16
pxl|pixel|canv|canvas size 16 16 | pxl|pixel|canv|canvas size 16
# set output resolution to 256x256
pxl|pixel|canv|canvas res 256 256 | pxl|pixel|canv|canvas res 256
# enable autodraw
pxl|pixel|canv|canvas autodraw true
# set pixel at 2|12 to color #F6F6F6
pxl|pixel|canv|canvas set 2 12 "F6"
# update matrix to screen
pxl|pixel|canv|canvas draw
## FUNCTIONS ##
# - functions have their own scopes
# - they can call other functions
# - their own vars are private
# - they can't acces root-scope's vars (except they were made global using `glob`)
# - args with $-prefix are copied into local scope
# - args with &-prefix are passed to parent scope
# the function scope "myfunction1" starts here
# argument $1 is readonly; $2 is read/write
fcn|def myfunction1 $1 &2
# current function scope ends here
end
# call a function called "myfunction1"
# arg $1 = 42; arg $2 = $test (returned to parent scope)
myfunction1 42 $test
## RETURN, END, ETC. ##
# halt the programm
halt
# return from function to parent scope
# halt programm in root scope
exit|return|end
## LISTS ##
# set $a to empty list
set $a []
# set $a to list
set $a [1, 5, 2345]
# print 2nd element of 4th list
echo $a[3][1]
# remove 2nd element
set $a[1] null
# push element
set $a[] "blabla" | add $a "blabla"
# print last element
echo $a[-1]
# remove (and get) last element
pop $a[-1] | pop $a[-1] $b
# get list length
len $list $length_num
## EXTERNAL VALUES ##
# get unix time
time $time
# get formated time
time $time "YYYY-MM-DD"
# get random integer between 0 and 3
rnd|rand|random $num 3
# get random integer between 5 and 13
rnd|rand|random $num 5 13
## STRING MANIPULATION ##
# get string lenght
len $string $length_num
# concat strings => $a
add $a $b ...
# get substr 2(-5)
slice|substr $string 2 5 | slice|substr $string 2
# repeat string
mul $string 3
# get position of first occourance of needle in haystack => $pos
# $pos >= 0 if found; $pos = false if nothing found
pos|strpos $haystack $needle $pos