Modul:Common: Unterschied zwischen den Versionen

isEmpty() Tabellencheck
(+ hasSemicolon())
Markierung: Zurückgesetzt
(isEmpty() Tabellencheck)
 
(27 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
local p = {}
local p = {}


function p.AttributeTable(args)
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.templateTranscludeWithArgs(frame)  
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 202: Zeile 226:
end
end


function p.hasSemicolon(frame)
function p.isTrue(s)
local has = false
-- testet String auf True-Werte verschiedenster Schreibweisen
    if string.find(frame:getParent():getTitle(),";") ~= nil then
local result = false
    has = true
if not p.isEmpty(s) then
    end
if type(s) == "number" then
    return has
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