July 2018
Beginner
202 pages
5h 42m
English
The next events debug.sethook can hook into are function calls. These events fire every time a function is called. The event handler only needs to take one argument, a string. The value of this string will always be "call". To subscribe to function call events, provide debug.sethook with two arguments: the handler function, and the "c" string. Function callback hooks become much more powerful when combined with the info obtained from debug.getinfo. The following code demonstrates this:
function PrintV(x, y, z) local out = "(" .. x .. "," out = out .. ", " .. y out = out .. ", " .. z .. ")" return outendfunction MagnitudeSq(x, y, z) local magSq = x * x + y * y + z * z return magSq;endfunction trace(event) local info = debug.getinfo(2) ...