diff --git a/doc/script/index.txt b/doc/script/index.txt index ea1ca308..85db02a3 100644 --- a/doc/script/index.txt +++ b/doc/script/index.txt @@ -12,3 +12,41 @@ MSE uses a custom scripting language to add complicated behaviour to [[type:fiel See also: * [[type:index|Data types used]] * [[fun:index|Built in functions]] + +--Syntax index-- +| @123@ [[type:int|A literal number]] +| @"stuff"@ [[type:string|A literal string]] +| @[a,b,c]@ [[type:list|A literal list]] +| @[a:b, c:d]@ [[type:map|A literal map]] +| @{ expr }@ [[script:variables#Functions|Function definition]] +| @fun(a:b, c:d)@ [[script:variables#Functions|Function call]] +| @fun(value)@ [[script:variables#Functions|Function call with '@input@' argument]] +| @fun@@(a:b)@ [[script:variables#Default arguments|Default arguments]] +| @a.b@ [[script:operators|Property 'b' of 'a']] +| @a[b]@ [[script:operators|Property 'value of b' of 'a']] +| @-a@ [[script:operators|Negation]] +| @a + b@ [[script:operators|Addition / concatenation]] +| @a - b@ [[script:operators|Subtraction]] +| @a * b@ [[script:operators|Multiplication]] +| @a / b@ [[script:operators|Floating point division]] +| @a div b@ [[script:operators|Integer division]] +| @a mod b@ [[script:operators|Remainder]] +| @not a@ [[type:boolean|Boolean not]] +| @a and b@ [[type:boolean|Boolean conjunction]] +| @a or b@ [[type:boolean|Boolean disjunction]] +| @a xor b@ [[type:boolean|Boolean xor]] +| @a == b@ [[script:operators|Comparison for equality]] +| @a != b@ [[script:operators|Comparison for inequality]] +| @a < b@ [[script:operators|Comparison]] +| @a > b@ [[script:operators|Comparison]] +| @a <= b@ [[script:operators|Comparison]] +| @a >= b@ [[script:operators|Comparison]] +| @a or else b@ Use @a@ unless it is an error, then use @b@ instead. +| @min(a,b,c,...)@ [[script:operators|Smallest of the values]] +| @max(a,b,c,...)@ [[script:operators|Largest of the values]] +| @rgb(r,g,b)@ [[type:color|A color value]] +| @rgba(r,g,b)@ [[type:color|A color value with transparency]] +| @if x then y@ [[script:control structures|Conditional expresion]] +| @if x then y else z@ [[script:control structures|Conditional expresion]] +| @for x in list do y@ [[script:control structures|Loop over elements in a list]] +| @for x from a to b do y@ [[script:control structures|Loop over numbers from a to b]] diff --git a/doc/script/variables.txt b/doc/script/variables.txt index 655bdc42..6498b508 100644 --- a/doc/script/variables.txt +++ b/doc/script/variables.txt @@ -74,4 +74,17 @@ This can be done by first making a copy, and calling that: > to_upper("xyz") == "upper case: XYZ" Note that @real_to_upper@ is called without extra parameters, the @input@ variable is still set from the outer call to the new @to_upper@ itself. +--Default arguments-- +It is possible to declare default arguments for functions using the @@@@ operator. +> function := { "argument was: " + arg }@(arg:"default") +If this function is called without the @arg@ argument, then the default value @default@ is used instead. +For example: +> function() == "argument was: default" +> function(arg: "something else") == "argument was: something else" +For determining whether the argument is set only explicit arguments count, not everything in scope, so +> arg := "something else" +> function() == "argument was: default" + +Defaults are evaluated at the time the @@@@ operator is evaluated, so they can be used to simulate static scoping. +