Difference between revisions of "Module:Silent1/sandbox"
Jump to navigation
Jump to search
m |
m |
||
Line 13: | Line 13: | ||
return loaded_data_modules[module_name][item] | return loaded_data_modules[module_name][item] | ||
+ | end | ||
+ | |||
+ | function p.addSeparator(num) | ||
+ | return tostring(num):reverse():gsub("(%d%d%d)","%1,"):gsub(",(%-?)$","%1"):reverse() | ||
end | end | ||
Line 19: | Line 23: | ||
local item = args[1] | local item = args[1] | ||
local multi = args[2] | local multi = args[2] | ||
+ | local separator = args[3] | ||
+ | local price = 0 | ||
if multi == nil then | if multi == nil then | ||
multi = 1 | multi = 1 | ||
end | end | ||
item = string.lower(item) | item = string.lower(item) | ||
− | + | price = p.loadPrice (item, 'price') * multi | |
+ | |||
+ | if separator == nil then | ||
+ | return price | ||
+ | else | ||
+ | return addSeparator(price) | ||
+ | end | ||
end | end | ||
return p | return p |
Revision as of 10:56, 10 February 2022
local p = {} local data_module_names = { price = 'Module:MarketPrices/data' } local loaded_data_modules = {} function p.loadPrice (item, data_type) local module_name = data_module_names[data_type] if loaded_data_modules[module_name] == nil then loaded_data_modules[module_name] = mw.loadData(module_name) end return loaded_data_modules[module_name][item] end function p.addSeparator(num) return tostring(num):reverse():gsub("(%d%d%d)","%1,"):gsub(",(%-?)$","%1"):reverse() end function p._price(frame) local args = frame:getParent().args local item = args[1] local multi = args[2] local separator = args[3] local price = 0 if multi == nil then multi = 1 end item = string.lower(item) price = p.loadPrice (item, 'price') * multi if separator == nil then return price else return addSeparator(price) end end return p