lua-users home
lua-l archive

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


On Tue, 2011-09-20 at 13:31 +0100, Robert Raschke wrote:
>         
>         When called with this test;
>         133     local s = pcall(filters:add(123))
>         134     assert( not s, "error expected because of a number")
> 
> You are invoking the function before allowing pcall() to do its thing.
> You probably want this:
> 
>    local s = pcall(add, filters, 123)
> 
> This invokes the function add on the remaining arguments in a
> protected manner.

That would work if 'add' was global or a local variable. Assuming only
'filters' is visible, this should be better:

    local s = pcall(filters.add, filters, 123)

filters:add(123) is sugar for filters.add(filters, 123)