Modul:Common: Unterschied zwischen den Versionen

isEmpty() Tabellencheck
Keine Bearbeitungszusammenfassung
(isEmpty() Tabellencheck)
 
(17 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 139: Zeile 146:


function p.append_tables(t1, t2)
function p.append_tables(t1, t2)
-- append indexes table to another
-- 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 147: Zeile 157:
table.insert(result, v)
table.insert(result, v)
end
end
mw.logObject(result)
return result
return result
end
end
Zeile 162: 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 187: 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 200: 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 215: Zeile 226:
end
end


function p.fullpagename()
function p.isTrue(s)
return tostring(mw.title.getCurrentTitle())
-- 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