Skip to Content
Lua Quick Start Guide
book

Lua Quick Start Guide

by Gabor Szauer
July 2018
Beginner
202 pages
5h 42m
English
Packt Publishing
Content preview from Lua Quick Start Guide

Return ("r")

The final type of hook is a return hook. Return hooks get executed every time a function returns, that is, when the return keyword is encountered. To subscribe to a return event, provide debug.sethook with two arguments: the handler function, and the "r" string.

The handler function takes only one argument, a string constant with the "return" value. This callback is similar to the function callback:

function Normalize(x, y, z)  local dot = x * x + y * y + z * z  if dot == 0 then    return nil  end  local len = math.sqrt(dot)  return {    x = x / len,    y = y / len,    z = z / len  }endfunction trace(event)  local info = debug.getinfo(2)  if info.what == "Lua" then    print ("event: " .. event)    print (" function: " .. info.name) print (" defined on: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Lua Programming

Beginning Lua Programming

Kurt Jung, Aaron Brown
Vim Masterclass

Vim Masterclass

Jason Cannon

Publisher Resources

ISBN: 9781789343229Supplemental Content