Line ("l")

The first type of debug.sethook event is the line event. This event is going to fire every time a line of code is being executed. If you've ever used a debugger that supports breakpoints, this is the functionality that could be used to implement breakpoints.

To subscribe to the line event, provide the debug.sethook function with two arguments, the even handler and the string "l". The handler function needs to take two arguments. The first argument is going to be a string, with the "line" value. The second argument is going to be an integer; this is the line number being executed:

function VectorLength(x, y, z)
local dot = x * x + y * y + z * z
if dot == 0 then
return nil
end
return math.sqrt(dot)
end

function trace(event, line)
print("event: " .. event)
print (" executing: line " .. line)
end

debug.sethook(trace, "l")

local x = 3
local y = 5
local z = 1
local len = VectorLength(x, y, z)
print ("length: " .. len)
..................Content has been hidden....................

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