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

Multiple hooks

Multiple hooks can be specified by adding a space and another letter to debug.sethook. For example, you could subscribe to every possible event, like so:

debug.sethook(trace, "l c r", 1)

When subscribing to multiple hooks, remember the callback's second argument is nil, except for the line event. Check for nil as appropriate. The following code demonstrates how to do this:

function trace(event, line)  local info = debug.getinfo(2)  if info.what == "Lua" then    print ("event: " .. event)    print (" function: " .. info.name)    print (" defined on: " .. info.linedefined)    if line ~= nil then      print (" called from: " .. line)    end  endend
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