Module:Autocategorizer

local p = {} local data = { ['games'] = { {           ['var'] = 'game_tnfs', ['category'] = 'The Need for Speed' },       {            ['var'] = 'game_2', ['category'] = 'Need for Speed II' },       {            ['var'] = 'game_3hp', ['category'] = 'Hot Pursuit' }   },    ['types'] = { ['car'] = 'Cars (%s)', ['character'] = 'Characters (%s)' } }

function getVariables( frame, vars ) return mw.text.split( frame:preprocess( '|' ), '|', true ) end

function p.categorize( frame ) local out = {} local vars_keys = { 'type' } for i,v in ipairs( data['games'] ) do       vars_keys[i+1] = v['var'] end

local vars = getVariables( frame, vars_keys ) if data['types'][vars[1]] then for i,v in ipairs( vars ) do           --mw.log( i, v, i > 1, v ~= '' ) if i > 1 and v ~= '' then out[#out+1] = string.format( '', data['types'][vars[1]]:format( data['games'][i-1]['category'] ) ) end vars_keys[i+1] = v['var'] end end return table.concat( out ) end

return p