1.一个示例实现列表的元素的求和
Lua
[root@]# more funcAdd.lua
function add(a)
local sum = 0
for i = 1,#a do
sum = sum + a[i]
end
return sum
end
a = {1,2,3,4,5,6}
local sum = add(a)
print(sum)