Zuweisung
Variablen sind dynamisch typisiert und standardmäßig local. Du kannst den Geltungsbereich mit den Statements local und global ändern.
hello = "world"a, b, c = 1, 2, 3hello = 123 -- nutzt die bestehende Variablehello = "world"a, b, c = 1, 2, 3hello = 123 -- nutzt die bestehende VariableUpdate-Zuweisung
Abschnitt betitelt „Update-Zuweisung“Du kannst Update-Zuweisungen mit vielen binären Operatoren durchführen.
x = 1x += 1x -= 1x *= 10x /= 10x %= 10s ..= "world" -- legt eine neue lokale Variable an, wenn sie nicht existiertarg or= "default value"x = 1x += 1x -= 1x *= 10x /= 10x %= 10s ..= "world" -- legt eine neue lokale Variable an, wenn sie nicht existiertarg or= "default value"Verkettete Zuweisung
Abschnitt betitelt „Verkettete Zuweisung“Mit verketteten Zuweisungen kannst du mehrere Variablen auf denselben Wert setzen.
a = b = c = d = e = 0x = y = z = f!a = b = c = d = e = 0x = y = z = f!Explizite Locals
Abschnitt betitelt „Explizite Locals“do local a = 1 local * print "forward declare all variables as locals" x = -> 1 + y + z y, z = 2, 3 global instance = Item\new!
do local X = 1 local ^ print "only forward declare upper case variables" a = 1 B = 2do local a = 1 local * print "forward declare all variables as locals" x = -> 1 + y + z y, z = 2, 3 global instance = Item\new!
do local X = 1 local ^ print "only forward declare upper case variables" a = 1 B = 2Explizite Globals
Abschnitt betitelt „Explizite Globals“do global a = 1 global * print "declare all variables as globals" x = -> 1 + y + z y, z = 2, 3
do global X = 1 global ^ print "only declare upper case variables as globals" a = 1 B = 2 local Temp = "a local value"do global a = 1 global * print "declare all variables as globals" x = -> 1 + y + z y, z = 2, 3
do global X = 1 global ^ print "only declare upper case variables as globals" a = 1 B = 2 local Temp = "a local value"