Module:ExchangeLite

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to: navigation, search
Module documentation
This documentation is transcluded from Module:ExchangeLite/doc. [edit] [history] [purge]

This module is a simpler version of Module:Exchange, designed to be used by most modules that only need to load a few GE prices. Loads data from Module:Exchange/Item name.

This module is a helper module to be used by other modules; it may not designed to be invoked directly. See RuneScape:Lua/Helper modules for a full list and more information. For a full list of modules using this helper click here

FunctionTypeUseExample
load{ item = string, dataType = string }tableLightweight version of Module:Exchange. Returns the data type requested for the specified item. Any of the fields of an exchange page can be used (see Module:Exchange/Fire rune)
price( item )stringReturns the Grand exchage price of item as a number.

-- <nowiki>
--
-- 
---- Lightweight version of Module:Exchange

local p = {}
local mwLoadData = mw.loadData

local function loadData( item )
    return mwLoadData( 'Module:Exchange/' .. item )
end

function p.load( t )
	if t.args then
		local args = t.args
		return loadData( args[1] )[args[2]]
	else
		return loadData( t.item or t[1] )[t.dataType or t[2]]
	end
end

function p.price( item )
	local data = mwLoadData( 'Module:GEPrices/data' )
	if data[item] then
		return data[item]
	end
	item = string.gsub( item or '', '&#0?39;', "'" ):gsub( '_', ' ' ):gsub( '  +', ' ' ):gsub( '^.', string.upper )
	return data[item]
end

return p
-- </nowiki>