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

181 lines
3.0 KiB
Bash
Raw Normal View History

2021-06-03 20:31:48 +02:00
## VARIABLES ##
# $2 => $1
2021-06-03 22:41:41 +02:00
mov|set $1 $2
2021-06-03 20:31:48 +02:00
# load $1 from root scope into current scope
2021-06-03 22:41:41 +02:00
glob|global|pub|public $1
2021-06-03 20:31:48 +02:00
# vartypes:
2021-06-03 22:41:41 +02:00
null # null
true|false # bool
eg. -44 27 287634 # int
eg. 4.0 -3.0 0.125 # float
eg. "bla" 'blub' # str
2021-06-03 20:31:48 +02:00
## MATH ##
2021-06-03 22:41:41 +02:00
# $1 + $2 + ... => $1
add $1 $2 ...
2021-06-03 20:31:48 +02:00
2021-06-03 22:41:41 +02:00
# $1 - ($2 + ...) => $1
sub $1 $2 ...
2021-06-03 20:31:48 +02:00
2021-06-03 22:41:41 +02:00
# $1 * $2 * ... => $1
mul $1 $2 ...
2021-06-03 20:31:48 +02:00
2021-06-03 22:41:41 +02:00
# $1 / ($2 * ...) => $1
div $1 $2 ...
2021-06-03 20:31:48 +02:00
2021-06-03 22:41:41 +02:00
# $1 % $2 % ... => $1
mod $1 $2 ...
# $1 ^ $2 ^ ... => $1
2021-06-04 12:46:34 +02:00
pow $1 $2 ...
2021-06-03 20:31:48 +02:00
## 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)
2021-06-03 22:41:41 +02:00
jmp|jump|goto 42
2021-06-03 20:31:48 +02:00
# jump to a flag called "flag1" (flags are stored per-scope)
2021-06-03 22:41:41 +02:00
jmp|jump|goto "flag1"
2021-06-03 20:31:48 +02:00
# set flag called "flag1"
:flag1 | :flag1: | flag1:
## OUTPUT ##
# print "blabliblub"
2021-06-03 22:41:41 +02:00
drw|draw|echo "bla" "bli" "blub"
2021-06-03 20:31:48 +02:00
# initialize matrix with 16x16
2021-06-03 22:41:41 +02:00
pxl|pixel|canv|canvas size 16 16 | pxl|pixel|canv|canvas size 16
2021-06-03 20:31:48 +02:00
# set output resolution to 256x256
2021-06-03 22:41:41 +02:00
pxl|pixel|canv|canvas res 256 256 | pxl|pixel|canv|canvas res 256
2021-06-03 20:31:48 +02:00
# enable autodraw
2021-06-03 22:41:41 +02:00
pxl|pixel|canv|canvas autodraw true
2021-06-03 20:31:48 +02:00
# set pixel at 2|12 to color #F6F6F6
2021-06-03 22:41:41 +02:00
pxl|pixel|canv|canvas set 2 12 "F6"
2021-06-03 20:31:48 +02:00
# update matrix to screen
2021-06-03 22:41:41 +02:00
pxl|pixel|canv|canvas draw
2021-06-03 20:31:48 +02:00
## 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
2021-06-03 22:41:41 +02:00
fcn|def myfunction1 $1 &2
2021-06-03 20:31:48 +02:00
# current function scope ends here
2021-06-03 22:41:41 +02:00
end
2021-06-03 20:31:48 +02:00
# call a function called "myfunction1"
# arg $1 = 42; arg $2 = $test (returned to parent scope)
myfunction1 42 $test
## RETURN, END, ETC. ##
2021-06-03 22:41:41 +02:00
# halt the programm
halt
2021-06-03 20:31:48 +02:00
# return from function to parent scope
# halt programm in root scope
2021-06-03 22:41:41 +02:00
exit|return|end
2021-06-03 20:31:48 +02:00
## LISTS ##
# set $a to empty list
set $a []
# set $a to list
set $a [1, 5, 2345]
2021-06-03 22:41:41 +02:00
# print 2nd element of 4th list
echo $a[3][1]
2021-06-03 20:31:48 +02:00
# remove 2nd element
set $a[1] null
# push element
2021-06-03 22:41:41 +02:00
set $a[] "blabla" | add $a "blabla"
2021-06-03 20:31:48 +02:00
# print last element
echo $a[-1]
# remove (and get) last element
pop $a[-1] | pop $a[-1] $b
2021-06-03 22:41:41 +02:00
# 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