Schokokex / addon_template_butt

A template for Dota But Mods. Initiated by Baumis Twitch/Youtube channel and the community.
https://www.twitch.tv/l34um1
22 stars 13 forks source link

function argument sorter #34

Open Schokokex opened 4 years ago

Schokokex commented 4 years ago

function argSorter(o,order,must) -- o: toSort args, order: {"function","string",..}, must:{true,false...}
 local out = {}
 for i,v in ipairs(order) do
  for _,v in pairs(o) do
   if order[i]==type(v) then out[i] = v break end
  end
  if nil==out[i] and must[i] then error(string.format("required %s not found",order[i]),3) end
 end
 return out[1],out[2],out[3] -- unpack fails if out[1]==nil
end