Closed zugzug90 closed 3 years ago
"safe" isn't really the right term here. And this seems like a very specific function for a very specific case.
print(inspect.inspect((two_values())))
It doesn't make sense to have an entirely new function instead of that.
Use a table to wrap all the possible values returned by the function. Instead of:
print(inspect(two_values())
Do this:
print(inspect({two_values()})
You can usually drop the two parenthesis of the call and just leave the brackets. This is equivalent to the previous one:
print(inspect{two_values()})
So inspect(call())
is "unsafe", but inspect{call()}
is "safe"
For cases when you need to print out whatsoever results of some function call you can use another version of
inspect
function:safe_inspect
. Usage scenario example below:Result will be:
This allows to prevent primitive type handling errors when using original
inspect
function by just throwing away all the rest returned values if they are not of thetable
type otherwise using 2nd arg as parameters map likeinspect
function does.See issue: https://github.com/kikito/inspect.lua/issues/39