@davebollinger
Thanks a lot! I understand it is very early, even more than I thought
@laurasweet8888
I do not think that’s what I need.What you have proposed, I think, is long and complex.
To answer your question “why you want to know if the first finalize was defined in the module ball”:
finalize it was just an example. The thing I need is to know, in a “quick” way, a function has been created with “.” or “:”.
Very often it happens that we use non-proprietary libraries or parts of code.
So I make a “stupid” example, I hope to make the idea:
My code:
-------- --ball-- -------- local M = {} function M.new() local obj = display.newCircle( 160, 250, 30 ) obj:setFillColor( 1, 0, 0 ) function obj:finalize() print("First finalize") end obj:addEventListener( "finalize" ) return obj end return M
external code:
------------------- --otherBall.lua-- ------------------- local M = {} function M.new() local obj = display.newCircle( 160, 250, 30 ) obj:setFillColor( 1, 0, 0 ) obj.finalize = function() print("First finalize other ball") end obj:addEventListener( "finalize" ) return obj end return M
in the my main
------------ --main.lua-- ------------ local ball = require("ball") local obj\_1 = ball.new() obj\_1.firstFinalize = obj\_1.finalize -- store it obj\_1.finalize = function(self) self:firstFinalize() -- call it print("Second finalize") end display.remove(obj\_1) local otherBall = require("otherBall") local obj\_2 = otherBall.new() obj\_2.firstFinalize = obj\_2.finalize -- store it obj\_2.finalize = function(self) self:firstFinalize() -- call it print("Second finalize") end display.remove(obj\_2)
In this example the finalize on the second object will not work and will give error.
I know that it would be enough to standardize the module “otherBall”.
But I’m fascinated by the idea of finding a solution that would automatically know if the object had a function. “” or “:” and acted accordingly.
I hope I explained. I’m not native speaker…