Passing of callback one level

Hi There!

I have an object ‘Block’. Within this block I have several properties, one of which is the graphical representation of the object (a sprite).

(Note, I am using the class implementation as found in numerous places throughout this community)

[lua]function block.new(id, btype, coords)

local newBlock = {
id = id or 0,
btype = btype or nil,
coords = coords or nil,
size = 0,
sprite = nil,
}
return setmetatable( newBlock, block_mt )
end[/lua]

Within this “class” I am performing a move of the sprite using the ‘transition.to()’ method. I would like to ignore the user pressing buttons until the transition is complete. I would like to do this by setting an inhibit flag when the movement begins and clear it on the event of the movement completing.

I have implemented the ‘onComplete’ callback and this is working successfully, but from my main lua, I would like to pass the callback up one level (i.e. invoke a callback of my ‘block’ object (e.g. ‘moveComplete’) and be able to listen to it from the main.lua file).

I would like to either (no real preference which - looking for your advice):
1/ use some event to call up to the main from the instance of the block class to alert the movement has completed

2/ be able to pass a callback into my ‘block:Move()’ function which I can call when the callback is fired in the 'block ’ object.

I am really looking for advice on how to implement this, if it’s even possible. I have done this in other languages, but being fairly new to Lua, I would appreciate some guidance, recommendation or even a quick link showing me how to do it.

Many Thanks.

BG [import]uid: 162435 topic_id: 31621 reply_id: 331621[/import]