Using debugger.lua

Lets take a look at an example of using debugger.lua. Consider the following buggy code:

local debug = require("debugger")

function BuggyAdditionFunction(x1, x2)
local sum = x1 * x2
debug()
return sum
end

local add = BuggyAdditionFunction(2, 3)
print(add)

Here, BuggyAdditionFunction multiplies the two arguments instead of adding them together. Notice the debug() command before the function returns. When this command is hit, control in the console will be given to the debugger. Type l and hit Enter to print the local variables. Doing so, it's easy to see that sum is wrong and needs to be fixed. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.114.19