Created
November 2, 2012 18:44
-
-
Save erinlin/4003474 to your computer and use it in GitHub Desktop.
Corona: extends Group example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------------------------------------------- | |
-- | |
-- extends Group example | |
-- | |
------------------------------------------------- | |
local group = {} | |
local group_mt = { __index = group } -- metatable | |
------------------------------------------------- | |
-- PRIVATE FUNCTIONS | |
------------------------------------------------- | |
------------------------------------------------- | |
-- PUBLIC FUNCTIONS | |
------------------------------------------------- | |
function group.new(params) -- constructor | |
local newGroup = display.newGroup() | |
local _group = newGroup | |
for k,v in pairs(params) do | |
_group[k]=v | |
end | |
local newGroup = {} | |
local group_mt = { | |
__index = function (t,k) | |
if(_group[k]) then | |
return _group[k] | |
else | |
return group[k] | |
end | |
end, | |
__newindex = function (t,k,v) | |
if(_group[k]) then | |
_group[k] = v | |
group[k] = v | |
else | |
_group[k] = v | |
group[k] = v | |
end | |
end | |
} | |
newGroup._proxy = _group._proxy | |
newGroup._userdata = _group._userdata | |
setmetatable( newGroup, group_mt ) | |
return newGroup | |
end | |
------------------------------------------------- | |
-- This is just example of how to create custom | |
-- OOP functions for all your display object. | |
function group:hello(target) | |
print( self.name .. " say hello to ", target.name ) | |
end | |
------------------------------------------------- | |
return group |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment