Module:SortItems

local p = {} local function _sortItems( nativeArgs, orderedList ) local sortedArgs = {} local ord = 1

for iOrd, bOrd in ipairs(orderedList) do       for iNat, bNat in ipairs(nativeArgs) do            if bOrd == bNat then -- add match to ordered list sortedArgs[ord] = bNat ord = ord + 1 break end end if (not nativeArgs[ord] or nativeArgs[ord] =='' ) then break -- found all arguments end end return sortedArgs end

function p.displayPigs( frame ) a = frame.args if (not a[1]) or (a[1] == '') then return '' else local sorted = _sortItems(a, mw.loadData('Module:OrderedListPigs')) return frame:expandTemplate{ title = 'ShowPigs', args = sorted } end end