Declarations and statements
var x T,var x T = e— explicit type;x := e— inferred frome(untyped constants default toint/float);nilcannot initialise:=.- Package-level
constonly; package-levelvarisAES1105. State lives in script fields and components. - Functions have fixed arity and zero or one result. A function that declares a result must end in a terminating statement (
AES2013). Recursion is allowed up to depth 256. if,if … else if … else;for cond {},for init; cond; post {},for {};break,continue.switch x { case a, b: … default: … }— no fallthrough; aswitchon an enum must cover every member or have adefault(AES2015); duplicate cases are errors.- Compound assignment
+= -= *= /= %=and++/--onint/floatlvalues; lvalues are variables, fields, lanes, slice elements, component fields and fields reached through aScriptRef. - A statement-level expression must be a call; an unused value is an error. Discarding the result of
len,append, a conversion,Get<T>,GetScript<T>orConnectis an error. Discarding the result ofstartis allowed. - Unused local variables are warnings.
- There are no closures, lambdas, defer, goroutines, pointers or maps.
Run it:
package demo
import "aego/log"
enum Weapon {
Sword
Bow
Staff
}
func damage(w Weapon) int {
switch w {
case Weapon.Sword:
return 12
case Weapon.Bow, Weapon.Staff:
return 8
}
return 0
}
func fib(n int) int {
if n < 2 {
return n
}
return fib(n - 1) + fib(n - 2)
}
script Statements {
func Ready() {
var total int
var scale float = 1.5
for w := 0; w < 3; w++ {
total += damage(Weapon(w))
}
log.Info("total damage " + string(total) + ", scaled " + string(float(total) * scale))
i := 0
for {
i++
if i % 2 == 0 {
continue
}
if i > 7 {
break
}
log.Info("odd " + string(i))
}
log.Info("fib(15) = " + string(fib(15)))
}
}