15.082
Bearbeitungen
Keine Bearbeitungszusammenfassung |
(isEmpty() Tabellencheck) |
||
| (44 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
local p = {} | local p = {} | ||
function p. | function p.attributeTable(args) | ||
-- Draws a simple Table that contains all arguments that are fed from the | -- Draws a simple Table that contains all arguments that are fed from the | ||
-- template to the scribunto-model. For debugging only! | -- template to the scribunto-model. For debugging only! | ||
| Zeile 90: | Zeile 90: | ||
function p.isEmpty(a) | function p.isEmpty(a) | ||
return a == '' or a == nil | if type(a) == "table" then | ||
for _ in pairs(a) do | |||
return false | |||
end | |||
return true | |||
else | |||
return a == '' or a == nil | |||
end | |||
end | end | ||
| Zeile 134: | Zeile 141: | ||
for k, v in pairs(t2) do | for k, v in pairs(t2) do | ||
result[k] = v | result[k] = v | ||
end | |||
return result | |||
end | |||
function p.append_tables(t1, t2) | |||
-- append indexed/keyed table to another | |||
-- indexes/keys gonna lost! | |||
-- the result is table with new indexes | |||
-- also see p.merge_tables() | |||
local result={} | |||
for _, v in pairs(t1) do | |||
table.insert(result, v) | |||
end | |||
for _, v in pairs(t2) do | |||
table.insert(result, v) | |||
end | end | ||
return result | return result | ||
| Zeile 149: | Zeile 171: | ||
function p.tableToString(tbl, indent) | function p.tableToString(tbl, indent) | ||
-- Prints a LUA-Table as string. Very useful if you want to see whats inside | -- Prints a LUA-Table as string. Very useful if you want to see whats inside | ||
-- to do: still neccessary? => mw.logObject() | |||
indent = indent or 0 | indent = indent or 0 | ||
local toprint = string.rep(" ", indent) .. "{\n" | local toprint = string.rep(" ", indent) .. "{\n" | ||
| Zeile 174: | Zeile 197: | ||
function p.shallowcopy(orig) | function p.shallowcopy(orig) | ||
-- real-copy of a table | |||
local orig_type = type(orig) | local orig_type = type(orig) | ||
local copy | local copy | ||
| Zeile 187: | Zeile 211: | ||
end | end | ||
function p. | function p.TemplateTranscludeWithArgs(frame) | ||
local args = p.shallowcopy(frame:getParent().args) -- frame:getParent().args als Basis nehmen | |||
local template = frame.args[1] -- enthält Vorlagen-Seitenname | |||
for orig_key, orig_value in pairs(frame.args) do -- über alle args iterieren, um parentargs mit args anzureichern | |||
if type(orig_key) == 'number' then -- bei numerierten Parametern... | |||
if orig_key > 1 then -- ... eine Index-Verschiebung durchführen, weil ... | |||
args[orig_key-1] = orig_value -- ... args[1] enthält Vorlagen-Seitenname, der | |||
end -- nicht übernommen wird | |||
else | |||
args[orig_key] = orig_value -- bei nicht-Nummern-Index 1:1 kopieren | |||
end | |||
end | |||
return frame:expandTemplate{title=template, args=args} | |||
end | |||
function p.isTrue(s) | |||
-- testet String auf True-Werte verschiedenster Schreibweisen | |||
local result = false | |||
if not p.isEmpty(s) then | |||
if type(s) == "number" then | |||
result = (s ~= 0) | |||
else | |||
s = tostring(s) | |||
result = ( s == "Ja" or s == "ja" or s == "Wahr" or s == "wahr" or s == "true") | |||
end | |||
end | |||
return result | |||
end | |||
function p.returnStringCheck(s) | |||
local t = "" | |||
local l = string.len(s) | |||
mw.smw.set({["LuaReturnLength"] = l}) | |||
if l > 100000 then -- aktuell Fehler ab ca. 450.000 | |||
t = t .. "[[Kategorie:Lua-String-Länge problematisch]]" | |||
end | |||
return t | |||
end | end | ||
return p | return p | ||