lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Here is a function that reads up to 10 numbers from a line:

function setup(line) 
    local data = {}
    while #data<10 do
        for w in line:gmatch("[^%s]+") do
            table.insert(data,(assert(tonumber(w),"Error")))
        for k=1,#data do print(k,data[k]) end
        break
        end
    end

E.g.
> setup("2 2 4 4 0 6 0 0")
1   2
2   2
3   4
4   4
5   0
6   6
7   0
8   0

Now, small change, remove the parentheses around the assertion.

            table.insert(data,assert(tonumber(w),"Error"))

Guess what happens before trying it!

Is this a newbie gotcha?

Dirk