Here is the version that works on any version of Lua 5.1 +.
local function WrapAndInspect(Inspector, FunctionToCall) local function Inspect(...) Inspector(...) return ... end local function Wrapper(...) return Inspect(FunctionToCall(...)) end return Wrapper end
What WrapAndInspect does, generates a function that will call that function, then passes its return values ββto the second function that you provide. This function can do whatever processing you think is necessary for them. But the structure ensures that the return values ββfrom the original function are passed as is.
Here's an option that does something similar, but instead of wrapping FunctionToCall , it returns a function that takes a function to be called (along with its parameters):
local function CallAndInspect(Inspector) local function Inspect(...) Inspector(...) return ... end local function Caller(FunctionToCall, ...) return Inspect(FunctionToCall(...)) end return Caller end
You can use this function for any specific function that you want to test.
source share