[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Function without return does not return nil?
- From: SH <sebastian.horlebein@...>
- Date: Thu, 9 Feb 2023 16:50:08 +0100
Putting parenthesis around the call should be enough.
Alternatively assign it to a variable befor further use or use pcall and handle the error.
If you expect return values you should print the user with an error.
Hello,
i have callback system where user registers own function. Some of these
functions do not return anything. I was expecting i can handle this
condition as nil. but apparently that is not the case. any ideas how can
i handle this situation?
> function a(); return nil; end;
> a
function: 0xaaab070bfaf0
> a()
nil
> tostring(nil)
nil
> tostring(a())
nil
> function b(); end;
> b
function: 0xaaab070c0de0
> b()
> tostring(nil)
nil
> tostring(b())
stdin:1: bad argument #1 to 'tostring' (value expected)
stack traceback:
[C]: in function 'tostring'
stdin:1: in main chunk
[C]: in ?
--
S pozdravem
Best regards
Tomáš Mudruňka - SPOJE.NET s.r.o.