[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Have you noticed how nil is a separate type?
- From: Martin <eden_martin_fuhrspam@...>
- Date: Tue, 21 Feb 2017 19:16:02 -0800
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.