Modul:X: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 14: | Zeile 14: | ||
function p.cut( frame ) | function p.cut( frame ) | ||
i = 1; | i = 1; --1 | ||
limit = tonumber(frame.args[1]) | limit = tonumber(frame.args[1]) --7 | ||
text = frame.args[2] | text = frame.args[2] --fiick dich halli | ||
stext = split(text, " ") | stext = split(text, " ")--fiick|dich|halli(list) | ||
cuttext = stext[1] | cuttext = stext[1]--fiick | ||
nextwo = stext[2] | nextwo = stext[2]--dich | ||
nextlen = string.len(nextwo) | nextlen = string.len(nextwo)--4 | ||
textlen = string.len(text) | textlen = string.len(text)--15 | ||
cuttextlen = string.len(cuttext) | cuttextlen = string.len(cuttext)--5 | ||
set = | set = true; | ||
if(limit>=textlen)then | if(limit>=textlen)then --7>=15 | ||
return text.."%@%" | return text.."%@%" | ||
elseif(cuttextlen>limit) then | elseif(cuttextlen>limit) then--5>7 | ||
return "%@%"..text | return "%@%"..text | ||
else | else | ||
while (cuttextlen+nextlen+1<textlen+3) do | while (cuttextlen+nextlen+1<textlen+3) do --5+4+1<15+3 | ||
if(cuttextlen+nextlen>limit and set) then | if(cuttextlen+nextlen>limit and set) then --5+4>7 | ||
set = | set = false | ||
cuttext = cuttext.."%@%" | cuttext = cuttext.."%@%" | ||
else | else |
Version vom 13. Januar 2020, 19:42 Uhr
Die Dokumentation für dieses Modul kann unter Modul:X/Doku erstellt werden
local p = {} --local p = {} -- p steht für Paket (engl. package)
function split (inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={}
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
function p.cut( frame )
i = 1; --1
limit = tonumber(frame.args[1]) --7
text = frame.args[2] --fiick dich halli
stext = split(text, " ")--fiick|dich|halli(list)
cuttext = stext[1]--fiick
nextwo = stext[2]--dich
nextlen = string.len(nextwo)--4
textlen = string.len(text)--15
cuttextlen = string.len(cuttext)--5
set = true;
if(limit>=textlen)then --7>=15
return text.."%@%"
elseif(cuttextlen>limit) then--5>7
return "%@%"..text
else
while (cuttextlen+nextlen+1<textlen+3) do --5+4+1<15+3
if(cuttextlen+nextlen>limit and set) then --5+4>7
set = false
cuttext = cuttext.."%@%"
else
cuttext = cuttext.." "
end
i = i + 1
cuttext = cuttext..nextwo
nextwo = stext[i]
nextlen = string.len(nextwo)
cuttextlen = string.len(cuttext)
end
return cuttext
end
end
return p