Types
| Type | Description |
|---|---|
bool |
true / false |
int |
signed 64-bit; wraps on overflow |
float |
IEEE float32 |
string |
immutable UTF-8; + concatenation, comparison, len in bytes; no indexing |
Vec2 Vec3 Color Quat Rect |
engine value types; lanes .X .Y .Z .W, .R .G .B .A, .X .Y .W .H |
Transform2D{Position Vec2, Rotation float, Scale Vec2} |
value struct |
Transform3D{Position Vec3, Rotation Quat, Scale Vec3} |
value struct |
NodeRef |
reference to a node; may be nil |
AssetRef<Texture | Scene | Prefab | Mesh> |
reference to an asset; may be nil |
ComponentRef<T> |
reference to a component on a node; may be nil |
ScriptRef<T> |
reference to an instance of script T; may be nil; fields, plain methods and signals of T |
Coroutine |
handle returned by start; may be nil; methods Stop(), Running() bool |
Connection |
handle returned by Connect; may be nil; methods Disconnect(), Connected() bool |
Curve |
read-only view of a curve field of a component (fader.Alpha); evaluated with aego/curve |
tween.Tween, timer.Timer, … |
host handles returned by engine and native modules; may be nil; methods come from the module |
struct |
package-level, value semantics, copied on assignment |
enum |
package-level, int-backed, members State.Idle |
[]T |
growable slice on the VM heap |
Rules:
- No implicit numeric conversion. Use
int(x),float(x),string(x)(frombool,int,float,string),int(e)for an enum andState(i)for int → enum. Untyped constants adapt to the context (var f float = 1is fine,var i int = 1.5is not). floatarithmetic is float32 everywhere, including constant folding.==/!=work on scalars, strings, enums, references, handles, vectors, structs with comparable fields, andTransform*;Quat,Curveand slices are not comparable.< <= > >=work on numbers and strings.- Vector arithmetic:
v + w,v - w,v * s,s * v,v / s,-v; vectors are constructed only with composite literals (Vec2{x, y},Color{1, 0, 0, 1}), never with call syntax. - A struct is a value:
a = bcopies; passing to a function copies. Nested structs are allowed, including structs from other packages; a struct that contains itself by value isAES2017. - A slice element may occupy at most 32 value slots (
AES2032); scalars, vectors, refs and small structs are far below it. nilis valid forNodeRef,AssetRef,ComponentRef,ScriptRef,Coroutine,Connectionand host handles. Reading or writing through a nil reference is a runtime fault (AES6004); calling a method on a nilCoroutine,Connectionor host handle is not:Running()andConnected()returnfalse,Done()returnstrue,Stop(),Cancel()andDisconnect()do nothing.
Run it:
package demo
import "aego/log"
type Stats struct {
Hp int
Armor float
}
enum Mood {
Calm
Angry
}
script Types {
var conn Connection
func Ready() {
a := Stats{Hp: 10, Armor: 0.5}
b := a
b.Hp = 3
log.Info("structs copy: a.Hp " + string(a.Hp) + ", b.Hp " + string(b.Hp))
f := 7.9
log.Info("int(7.9) = " + string(int(f)) + ", float(7) / 2 = " + string(float(7) / 2) + ", 7 / 2 = " + string(7 / 2))
m := Mood(1)
log.Info("Mood(1) is Angry: " + string(m == Mood.Angry) + ", int " + string(int(m)))
v := Vec2{3, 4} * 2 - Vec2{1, 1}
c := Color{1, 0.5, 0, 1}
log.Info("vector " + string(v.X) + ", " + string(v.Y) + ", color green " + string(c.G))
var hits []int
hits = append(hits, 5)
hits = append(hits, 7)
log.Info("slice of " + string(len(hits)) + ", last " + string(hits[len(hits) - 1]))
log.Info("nil connection connected: " + string(conn.Connected()))
}
}