Functions
Below is a list of GarmScript functions and their uses with examples and structure.
"setvar (variable) (value)" will define a variable.
"if (var 1) (== or /= or >> or << or =< or >=) (var 2)" will execute all code from the if statement to the word "end" if the statement is true.
"wait ___" will wait the number of seconds given.
"loop ___" will loop all code between the loop and the word "end" the amount of times given.
"readinput" will get user input using the python input() function.
readinput testvariable Input? :
"slice (string variable) (index 1) (index 2)" will slice a string between the two indexes and set the string to the result.
% This will get the characters of string teststringvar from index 0 to index 5
slice teststringvar 0 5
"arrayset (array) (append/remove/lengthof/index/atindex) (modifer) (result var)" will handle and control arrays.
% This defines the variable "result"
setvar result ""
% This will get the value of the array testarr at the first index and save it to variable "result"
arrayset testarr atindex 0 result
"pyrun" will execute Python code inline, use \ after each line of code to execute multiple lines.
% This will print "HELLO WORLD" using python code
pyrun \
print("HELLO WORLD") \
"jsrun" will execute JavaScript code inline.
% This will print "HELLO WORLD" using JavaScript code.
jsrun console.log("HELLO WORLD");
"find (result variable) (string) (subsring)" will return if substring is in string as boolean.
"usemod (filename) (function)" will use a ".mgarm" file or python file as a module and execute the given function from that file.
See modules documentation
"searcher (string) (expression) (result variable)" will use the expression given as explained below, to get a substring from a string similar to regex.
Expressions use the following:
"<*>" will match any non-whitespace character.
"
"math (+ or - or * or / or mod or exp or round) (result variable) (number 1) (number 2)" will perform arithmetic functions using the two numbers and save the result to the given variable.
% This will add 5+5 and save 10 to the variable "result"
setvar result 0
setvar numberone 5
setvar numbertwo 5
math + result numberone numbertwo
"getcmd (var name)" will get the output of the last shell command and store it as a variable.
"concat (result var) (string 1) (string 2)" will concat two strings.
"getdata (result var) (url)" will make a REST API request the the url and save the result as a variable.
"senddata (variable) (url)" will make a POST REST API request to the given url using the given variable.
"hostdata (variable) (path)" will host the given variable on a flask REST API server.
"snip (function name) {code}" will make a small snippet of code similar to a function but without arguments.
"iterate (varname) (string to iterate) (function)" will iterate over a string similar to a for loop and execute the given function each time.
% This will iterate over the characters in the string HELLO and execute the snippet testfunc each time.
snip testfunc {echo $char}
setvar teststring HELLO
iterate char teststring
"setobj (name) (functions array) (variables array)" will create a object with set snippets and variables, see example below.
% This will create two snippets and add them to the object helloworld then will call the function testone.
snip testone {echo HELLO}
snip testtwo {echo WORLD}
setobj helloworld [testone,testtwo] []
@helloworld testone []
"getobjvar (obj name) (var name) (result var)" will get a set variable from a object and save the result to the given variable.