30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | function queue(first,last) local func = function (tab) local tab = tab local function adiciona(valor) table.insert(tab,1,valor) end return func --retorna a funcao interna end return { add= function(valor) adiciona(valor) end, total= function () local m=0; local n=first while(assert(tab[n]) and n <= last)do m=tab[n]+m n=n+1 end return m, m/(last-first) --retorna o total e a media end, } end
|