lua-users home
lua-l archive

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


Function that returns nothing seems different than function that returns `nil`:

```lua
function f()
    return nil
end

function g()
end

print(f()) -- prints nil
print(g()) -- prints empty line
```

How to recognize this at the function call? For example how to implement an universal wrapper that would suppress all errors and still returns exactly the same thing as wrapped function in case of success?

```lua
function supperess(f, ...)
    success, result = pcall(f, ...)
    return result
end

print(supperess(f)) -- prints nil
print(supperess(g)) -- also prints nil, how to fix it?
```