Module:Data

From Feed The Beast Wiki
Jump to: navigation, search

Documentation for this module may be created at Module:Data/doc

local p = {}
function p.data( f )
	local args = f:getParent().args
	local data = mw.loadData( 'Module:' .. args.data )
	
	local value = data
	local case = args.lcase
	for k, v in ipairs( args ) do
		v = mw.text.trim( v )
		if case then
			v = mw.ustring.lower( v )
		end
		
		value = value[v]
		if not value then
			return args.default or args[1]
		end
	end
	
	if type( value ) == 'table' then
		-- loadData tables don't work with table.concat
		local concatValue = {}
		for _, v in ipairs( value ) do
			table.insert( concatValue, v )
		end
		
		value = table.concat( concatValue, ( args.separator or '' ) .. ' ' )
	end
	
	return value
end
return p