Module:PickRow: Difference between revisions
Appearance
Created page with "local p = {} local column = 0 function p.pick_row(tab, args) if args.column > 0 then column = args.column end for _, row in ipairs(tab.data) do if row[column] ~= args.filter then for c, _ in ipairs(row) do row[c] = 0 end end end return tab end return p" |
No edit summary |
||
| (5 intermediate revisions by the same user not shown) | |||
| Line 3: | Line 3: | ||
function p.pick_row(tab, args) | function p.pick_row(tab, args) | ||
if args.column > 0 then | if tonumber(args.column) > 0 then | ||
column = args.column | column = tonumber(args.column) | ||
end | end | ||
for | for i, row in ipairs(tab.data) do | ||
if row[column] ~= args.filter then | if row[column] ~= args.filter then | ||
for c, _ in ipairs(row) do | for c, _ in ipairs(row) do | ||
row[c] = 0 | if tab.schema.fields[c].type == "number" then | ||
row[c] = 0 | |||
end | |||
end | end | ||
end | end | ||
end | end | ||
return tab | return tab | ||
end | |||
-- Put p.test() in the debug console while you're editing the code to test | |||
-- with a specific sample data set / args | |||
function p.test(column, filter, tabname) | |||
-- pass "_" for lang to get the raw multilingual source data | |||
local tab = mw.ext.data.get(tabname or "Test.tab", "_", "LocalData") | |||
local args = { | |||
["column"] = column or 1, | |||
["filter"] = filter or "Tijgertje I" | |||
} | |||
tab = p.pick_row(tab, args) | |||
return mw.dumpObject(tab) | |||
end | end | ||
return p | return p | ||
Latest revision as of 20:58, 11 January 2026
Documentation for this module may be created at Module:PickRow/doc
local p = {}
local column = 0
function p.pick_row(tab, args)
if tonumber(args.column) > 0 then
column = tonumber(args.column)
end
for i, row in ipairs(tab.data) do
if row[column] ~= args.filter then
for c, _ in ipairs(row) do
if tab.schema.fields[c].type == "number" then
row[c] = 0
end
end
end
end
return tab
end
-- Put p.test() in the debug console while you're editing the code to test
-- with a specific sample data set / args
function p.test(column, filter, tabname)
-- pass "_" for lang to get the raw multilingual source data
local tab = mw.ext.data.get(tabname or "Test.tab", "_", "LocalData")
local args = {
["column"] = column or 1,
["filter"] = filter or "Tijgertje I"
}
tab = p.pick_row(tab, args)
return mw.dumpObject(tab)
end
return p