lua-users home
lua-l archive

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


On 02/20/2017 03:36 PM, Soni L. wrote:
> 
>     local function f(x)
>       --assert(type(x) == "function")
>       return {dothing=x}
>     end
> 
>     local v = f(nil)
> 
>     v:dothing()
> 
> If you
> uncomment the assertion, you get an error on line "local v = f(nil)"
> instead, which is much more helpful.

I think official way to handle this is change assert() to error() which
can specify in second parameter level of code that should take
resposibility.

  if (type(x) ~= "function") then
    error('wrong arg type passed', 2)
  end

I've implemented similar functionality as family of assert_nil(),
assert_boolean(), ... global functions.