Module:InventoryFormatter

local InventoryFormatter = {}

local outermostFormatString =  %s

local equippedFormatString =  Equipped %s

local carriedFormatString =  Carried %s

local itemFormatString =  x%s

local function formatItem(item) return itemFormatString:format(item.name, item.quantity) end

local function formatItems(formatString, items) if #items > 0 then local itemsString = ''

for _, item in ipairs(items) do           itemsString = itemsString .. formatItem(item) end

return formatString:format(itemsString) else return '' end end

--[[   Example usage:

Each item comprises three arguments, which are, in order:

- its display name - its quantity - "yes" if it's equipped, or anything else if it's not --]] function InventoryFormatter.format(frame) local args = frame.args local equippedItems, carriedItems = {}, {}

for n = 1, #args, 3 do       local name, quantity, equipped = args[n], args[n + 1], args[n + 2] local item = { name = name, quantity = quantity, }       local list = equipped == 'yes' and equippedItems or carriedItems table.insert(list, item) end

return outermostFormatString:format(       formatItems(equippedFormatString, equippedItems) ..        formatItems(carriedFormatString, carriedItems)) end

return InventoryFormatter