-- Kommentar
-- [[
Blockkommentar
-- ]]
-- String-Delimiter " und ' sind gleichwertig
a = "abc" .. 'def'
bool = true or false
true_value = '' or 0 or anyThingButFalse()
false_value = nil or false
bool2 = not bool
-- Assignments:
a = 3
-- Ersatz für cond ? alt1 : alt2:
val = cond and alt1 or alt2
-- comment
if a == "a" and b ~= "b" or not testIt() then
local c = a .. "Hi"
elseif c < 2 then
print('Hi')
end
while x < 3 do
print(x)
end
repeat
do_it(1)
until test_it(b)
-- Auswertung der 3 Parameter von for ist einmalig!
for ii=start,end,step do
print(ii)
end
for ii=0,12 do
print(ii)
if ii==stopper then
break
end
end
-- print all values of array `a'
for i,v in ipairs(a) do print(v) end
-- automatische Wandlung von String:
ix = "4" + ix2
a = "hi " .. b .. "!"
-- Suche
start,end = string.find(heap, needle, startIx, plain)
i1,i2 = string.find("long sentence with words", "o")
-- returns 2, 2
found = string.match("long sentence with words", "o")
-- returns "o2
-- Assoziatives Array:
a = { ['name'] = 'Jonny', ['email'] = 'a@b.c' }
if a['name'] then print("name found!") end
arr = { 1, 2, 3 }
-- der Startindex ist normalerweise 1, muss aber nicht sein:
a = {}
for i=-5, 5 do
a[i] = ii + 100
end
if a[-5] ~= 100 - 5 then
error("wrong")
end
-- 2-dimensionales Array:
mt = {} -- create the matrix
for i=1,N do
mt[i] = {} -- create a new row
for j=1,M do
mt[i][j] = 0
end
end
-- Start:
list = nil
-- Erster Eintrag:
list = {next = list, value = 99}
-- Suchen:
local l = list
while l do
print(l.value)
l = l.next
end
access_by_lua '
local ix1,ix2 = string.find(ngx.var.http_accept_language, "de", 1, true)
if ix1 == 1 then
if string.find(ngx.var.uri, "/de/", 1, true) then
ngx.redirect("https://frei-netz.org")
end
end
';