Module:Table/Wrench: Difference between revisions
From Growtopia Wiki
More actions
mNo edit summary |
mNo edit summary |
||
| Line 2: | Line 2: | ||
function p.build_table(frame) | function p.build_table(frame) | ||
return '' | local args = frame:getParent().args | ||
local data = args['data'] or '' | |||
if args == '' then | |||
return '' | |||
end | |||
local lines = mw.text.split(data, "\n") | |||
local results = {} | |||
for _, line in ipairs(lines) do | |||
line = mw.text.trim(line) | |||
if line ~= "" then | |||
line = line:gsub("%s*%$%$%$", "") | |||
local parts = mw.text.split(line, "|") | |||
local month = parts[1] or "" | |||
local item = parts[2] or "" | |||
-- 4. Insert into a Lua table | |||
table.insert(results, { | |||
month = mw.text.trim(month), | |||
item = mw.text.trim(item), | |||
}) | |||
end | |||
end | |||
for _, row in ipairs(items) do | |||
table.insert(output, "* " .. row.month .. " | [[" .. row.item .. "]]\n") | |||
end | |||
return table.concat(output) | |||
end | end | ||
return p | return p | ||
Revision as of 06:52, 5 April 2025
Documentation for this module may be created at Module:Table/Wrench/doc
local p = {}
function p.build_table(frame)
local args = frame:getParent().args
local data = args['data'] or ''
if args == '' then
return ''
end
local lines = mw.text.split(data, "\n")
local results = {}
for _, line in ipairs(lines) do
line = mw.text.trim(line)
if line ~= "" then
line = line:gsub("%s*%$%$%$", "")
local parts = mw.text.split(line, "|")
local month = parts[1] or ""
local item = parts[2] or ""
-- 4. Insert into a Lua table
table.insert(results, {
month = mw.text.trim(month),
item = mw.text.trim(item),
})
end
end
for _, row in ipairs(items) do
table.insert(output, "* " .. row.month .. " | [[" .. row.item .. "]]\n")
end
return table.concat(output)
end
return p