So I’ve run across a problem that has been addressed in other languages but not in Corona/Lua. How does one remove an event listener with an anonymous function?
It would seem that one is supposed to ‘store a reference to the function’ but I’m not sure of the syntax for that in Lua. I’ve spent some time looking it up, and the closest match I could find was this answer, which isn’t very helpful to me, being in Javascript and all.
Lua has no such thing as “remove event listener”. This is handled by libraries/frameworks that use event listeners, in your case Corona. I have no experience with Corona, but have you looked at removeEventListener() documentation?
It seems you just need to save the reference to your listener to be able to remove it later. That is, instead of doing this:
Do this: