15.080
Bearbeitungen
(fullpagename() moved to Modul:Wiki) |
(isEmpty() Tabellencheck) |
||
| (12 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 139: | Zeile 146: | ||
function p.append_tables(t1, t2) | function p.append_tables(t1, t2) | ||
-- append | -- append indexed/keyed table to another | ||
-- indexes/keys gonna lost! | |||
-- the result is table with new indexes | |||
-- also see p.merge_tables() | |||
local result={} | local result={} | ||
for _, v in pairs(t1) do | for _, v in pairs(t1) do | ||
| Zeile 161: | 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 186: | 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 199: | Zeile 211: | ||
end | end | ||
function p. | function p.TemplateTranscludeWithArgs(frame) | ||
local args = p.shallowcopy(frame:getParent().args) -- frame:getParent().args als Basis nehmen | local args = p.shallowcopy(frame:getParent().args) -- frame:getParent().args als Basis nehmen | ||
local template = frame.args[1] -- enthält Vorlagen-Seitenname | local template = frame.args[1] -- enthält Vorlagen-Seitenname | ||
| Zeile 215: | Zeile 227: | ||
function p.isTrue(s) | function p.isTrue(s) | ||
-- testet String auf True-Werte verschiedenster Schreibweisen | |||
local result = false | local result = false | ||
if not p.isEmpty(s) then | if not p.isEmpty(s) then | ||
if type(s) == "number" then | if type(s) == "number" then | ||
result = s | result = (s ~= 0) | ||
else | else | ||
result = ( s == "Ja" or s == "ja" or s == "Wahr" or s == "wahr" or s == "true | s = tostring(s) | ||
result = ( s == "Ja" or s == "ja" or s == "Wahr" or s == "wahr" or s == "true") | |||
end | end | ||
end | end | ||
return result | 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 | ||