Well, first thing I would do is to encapsulate your OOP in a base class, which allows the creation of new classes/prototypes and nothing else, and then derive everything from that ; I tend to use :
G.Base = \_G.Base or { new = function(s,...) local o = { } setmetatable(o,s) s.\_\_index = s o:initialise(...) return o end, initialise = function() end }
Metatables are kind of like ‘behaviour modifier’ for tables. So when you do .__index on the metatable, it is like saying, for the table that uses this, look here for unknown table members - the net effect of this is it looks in the metatable for the unknown element, allowing you to create a chain.
The above code breaks down as
local o = {} create a new table - this will either be a new class or an instance - in reality they are all prototypes
setmetatable(o,s) use ‘s’ as this objects metatable, this is the parent prototype.
s.__index = s when you can’t find something look for it in the metatable.
o:initialise(…) call the constructor
then there’s just a dummy constructor.
The answer to your question, I think, is that you have your event listener as a function listener, you should make it a table listener, so it calls joystick.touch with two parameters self and e (or call joystick:touch with one parameter, same difference).
Generally when writing OOP code (not always) you should be using : for methods and . for members.
Also, it is not a good idea to create mixin classes out of Corona objects unless you really have to. This may involve writing some adapter code - a move() method rather than assigning x and y, but it does save a lot of issues, because you cannot guarantee what Corona will do with their objects. The most obvious problem is when you try to set the metatable of joystick (itself a displayGroup), I’m pretty sure Corona have already done this as it is the descendant of some other object. When you do mixin classes you really have to decorate.
I wrote something similar https://github.com/autismuk/Executive/blob/master/utils/controller.lua ; this is for my own object system which has its own constructors and destructors but it should help you get the general idea
Corona does not normally have automatic destructors. Aside from the constructor() destructor() stuff (and the self:name() call) it is pretty much normal lua.