View Single Post
06/14/20, 11:40 AM   #1
QuantumPie
AddOn Author - Click to view addons
Join Date: Sep 2019
Posts: 32
Passing parameter to a callback function

When using a callback function with RegisterForEvent, is there a way I can specify a parameter that the callback uses? For example:

Lua Code:
  1. EVENT_MANAGER:RegisterForEvent(BarTracker.name, EVENT_ACTION_LAYER_PUSHED, BarTracker.toggleVisibility)
  2.  
  3. function BarTracker.toggleVisibility(hidden)
  4.     BarTracker.guiWindow:SetHidden(hidden)
  5. end

I can't simply pass BarTracker.toggleVisibility(true) as the 3rd parameter since that immediately invokes the function. In JavaScript, I could use bind or the syntax (() => BarTracker.toggleVisibility(true)) since that won't invoke it, but still passes the parameter when the callback is called. Does Lua have something similar? I don't know exactly what this is called so I couldn't find anything on SO.
  Reply With Quote