return an display.newGroup in a metatable in an external module

I was wondering how can I return an display.object to my main.lua

it is like this

metatabletest.lua

local test = {} local test\_mt = { \_\_index = test } function test.new( x, y, width, height ) local img = display.newRect( x, y, width, height ) local newtest = { image = img } -- newtest is a table now, fit to be use in setmetatable return setmetatable( newtest, test\_mt ) end function test:rollOver() print( self.image.x, self.image.y ) end return dog

main.lua

local metaTest = require 'metatabletest' local rst1 = metaTest.new(10,10,10,10) rst1:rollOver() -- prints 10, 10

cuz i want it to be inserted in a group but an error always occur

main.lua with group

local metaTest = require 'metatabletest' local gt = display.newGroup() local rst1 = metaTest.new(10,10,10,10) rst1:rollOver() -- prints 10, 10 gt:insert(rst1)--error goes here

stack trace:

File: main.lua Line: 7 Bad argument #-2 to 'insert' (Proxy expected, got nil) stack traceback: [C]: in function 'insert' main.lua:7: in main chunk

please help, thanks

Would it not be:

[lua]

gt:insert(rst1.image)

[/lua]

Or can you pass the display group to your test.new function as an optional parameter, and insert the image if the group parameter is not nil?

It works, how about If I have 2 images in test.new() in test.lua it works with only one, but the other doesn’t go with it

Done it, thanks for the tip man :slight_smile: really helps a lot :))

Would it not be:

[lua]

gt:insert(rst1.image)

[/lua]

Or can you pass the display group to your test.new function as an optional parameter, and insert the image if the group parameter is not nil?

It works, how about If I have 2 images in test.new() in test.lua it works with only one, but the other doesn’t go with it

Done it, thanks for the tip man :slight_smile: really helps a lot :))