Module:CargoVardefines

local p = {} function p.cargoVardefines (frame) -- Get args if frame == mw.getCurrentFrame then tpl_args = require( 'Module:ProcessArgs' ).merge( true ) else frame = mw.getCurrentFrame end -- All arguments that are for the query will start with q?	local cargoquery = {} for key, value in pairs(tpl_args) do if string.sub(key, 0, 2) == 'q?' then -- if first two characters are q?			cargoquery[string.sub(key, 3)] = value -- the rest of the string becomes the key for the cargo query table end end -- q?tables and q?fields are mandatory, the rest of the fields (if there are any) are added as extra args local result = mw.ext.cargo.query(cargoquery.tables, cargoquery.fields, cargoquery) if #result ~= 0 then for _, row in ipairs(result) do			for field, value in pairs(row) do				frame:callParserFunction('#vardefine', field, value) end end else local aliasname = "" local defaults = {} local default = tpl_args['default'] or 'Undefined' if tpl_args['defaults'] then for item in string.gmatch(tpl_args['defaults'], '[^,]+') do				mw.text.trim(item) key, value = string.match(item, "(.*)=(.*)$" ) defaults[key] = value end end for item in string.gmatch(cargoquery.fields, '[^,]+') do			aliasname = string.match(item, "=(.*)$" ) or item varname = string.match(item, "^([^=]*)") defaultname = defaults[varname] or default frame:callParserFunction('#vardefine', aliasname, defaultname) end end end return p