Module:Coin expr

local trim = mw.text.trim local iteminfo = require('Module:Iteminfo').getItemStat

local currentFrame local args_table

local getArg = function(key) local value = args_table[key] if not value then return nil end value = trim(value) return value end

- -- main return object return { go = function(frame, args) currentFrame = frame args_table = frame:getParent.args local sell = frame.args['sell'] local str = '' local errorStr = '' local i = 0 while true do		i = i+1 local arg = getArg(i) if arg == nil then break end if i % 2 == 0 then str = str .. arg else local itemid local itemname if type(tonumber(arg)) == 'number' and string.byte(arg) ~= 43 and string.byte(arg) ~= 45 then --tonumber accepts '+' and '-' at the start of the string, so we need to manually exclude that itemname = frame:expandTemplate{ title='itemNameFromId', args={arg} } else itemid = tonumber(frame:expandTemplate{ title='itemIdFromName', args={arg} }) end if arg ~= '' then if not itemid and not itemname then errorStr = errorStr .. 'Parameter ' .. i .. ' is not a valid item name or ID (Value: )! '				else if not itemid then itemid = tonumber(arg) -- if arg was item ID, then itemid was not set above, so we catch up here end local coinvalue = iteminfo(itemid, 'value') if sell then coinvalue = math.floor(coinvalue/5) end str = str .. coinvalue end end end end if errorStr ~= '' then local t = (sell and 'sell' or 'buy') .. ' expr' local tl = frame:expandTemplate{ title='tl', args={t} } errorStr = 'Error in ' .. tl .. ': ' .. errorStr return frame:expandTemplate{ title='error', args={errorStr} } else str = currentFrame:callParserFunction( '#expr', str ) if getArg('raw') then return str else local round = getArg('round') or 999 return frame:expandTemplate{ title='coin', args={str, round=round} } end end end

}