lua-users home
lua-l archive

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

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. 

Tomas Mudrunka <> schrieb am Do. 9. Feb. 2023 um 16:27:
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()
> tostring(nil)
> tostring(a())
> function b(); end;
> b
function: 0xaaab070c0de0
> b()
> tostring(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.