Module:Food/table/data

-- Lua implementation of Food/table/data. local p = {} local getArgs = require('Module:Arguments').getArgs local slot = require('Module:Inventory slot').slot local expr = mw.ext.ParserFunctions.expr

local function fst(t) if type(elem) == 'table' then return t[1] else return t	end end

local function map(t, f)   local r = {} for k,v in pairs(t) do       r[k] = f(v) end return r end

-- Main entry point function p.ftd(f) local args = {} if f.args ~= nil then args = getArgs(f) else args = f		f = mw.getCurrentFrame end

-- Normalize some names. args.name = args.name or args[1] args.hun = args.hun or args[2] args.sat = args.sat or args[3] args.src = args.src or args[4] args.link = args.link or args.name -- Preprocess. local only_je local only_be local diff = false if args.hun ~= nil then args.hun = tonumber(args.hun) end if args.sat ~= nil then if strings.find(args.sat, '\\') ~= nil then args.sat = mw.text.split(args.sat, '\\', true) args.sat = map(args.sat, tonumber) diff = true only_je = f:expandTemplate{ title = 'Template:Only', args = {'java', short=1} }			only_be = f:expandTemplate{ title = 'Template:Only', args = {'be', short=1} }		else args.sat = tonumber(args.sat) end end if args.poison ~= nul then args.poison = tonumber(expr(args.sat)) end -- Start emitting. local out_table = {} -- begin row out_table.insert('|-') -- link out_table.insert('!scope="row" id="args.name"|' ..		( .. args.name ) ..		(args.note and '&#x20;' .. args.note or '')	) -- pic out_table.insert('|' ..		slot({args.name, ['link']=args.link})	) -- hun out_table.insert('|' ..		f:expandTemplate{			title = 'Template:Hunger',			args = {args.hun}		}	) -- sat if args.sat ~= nil then out_table.insert('|' ..			(args.poison and 'data-sort-value=' .. tostring(fst(args.sat) - 0.01) .. '|' or '') ..			(diff and args.sat[1] .. only_je .. ' ' .. args.sat[2] .. only_be or args.sat)		) else out_table.insert('| ?') end if args.sat ~= nil and args.hun ~= nil then -- total local total if diff then total = {args.sat[1] + args.hun, args.sat[2] + args.hun} else total = args.sat + args.hun end out_table.insert('|' ..			(args.poison and 'data-sort-value=' .. tostring(fst(total) - 0.01) .. '|' or '') ..			(diff and (total[1] .. (args.poison and ' (' .. total[1] - args.poison .. ')' or '') .. only_je) .. ' ' ..					(total[2] .. (args.poison and ' (' .. total[2] - args.poison .. ')' or '') .. only_be) or (total .. (args.poison and ' (' .. total - args.poison .. ')' or '')) )		)		-- ratio else out_table.insert('| ?') out_table.insert('| ?') end

return tostring( body ) end