[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Correction Function
- From: Dan - Lintouch user <automacaovida-d2@...>
- Date: Thu, 16 Nov 2006 23:57:58 +0000 (GMT)
--******************** Based this sample, builder code bottom
function range_insert(first, last)
local func = function (tab, val)
local tab = tab
assert(last > first, "Illegal range - first index is greater than last.")
-- assert(tab >= last+1, "Last index in the range is greater than the length of the table.")
table.insert(tab, first, val)
table.remove(tab, last+1)
return tab
end
return func
end
--************ end sample
Make this function, have error associate function adiciona.
Please, correction, correct code;
--**************** Code Complete ******************
-- ############# function fluxo
function fluxo(first,last)
local func = function (tab)
local tab = tab{n=60} --create line matriz
assert(last > first, "Illegal range - first index is greater than last.")
assert(tab >= last+1, "Last index in the range is greater than the length of the table.")
--Funcao interna a func()
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
-- ******** end function
--Test start
queue=fluxo(5,10) -- Now have table queue={n=60}.
--Working range 5 to 10
for k=1,15,3 do
queue.add(k)
end
h,e=queue.total()
print (h.." "..e)
-- **************** end complete code
Yahoo! Search
Música para ver e ouvir: You're Beautiful, do James Blunt