Modules and returning functions

Hello,

I have a few questions about modules and returning functions from them

i have an object in main file that created using a module from another file and in that module creating another object from another module

question is: how can i access function(that will change or somehow be used with object in this module) from second module in main file? I tried to return object and functions in table, but it was not working for me

i hope its making any sense,any help would be appreciated [import]uid: 16142 topic_id: 15888 reply_id: 315888[/import]

http://blog.anscamobile.com/2011/09/a-better-approach-to-external-modules/

This should help! [import]uid: 64174 topic_id: 15888 reply_id: 58762[/import]

thanks for answer, but that is not something i need right now [import]uid: 16142 topic_id: 15888 reply_id: 58764[/import]

I do not fully understand.

Do you want to call a function defined in,say “second.lua” from “main.lua” and that function should modify an object which was created in “main.lua”???

[import]uid: 64174 topic_id: 15888 reply_id: 58765[/import]

that function should modify object created in second.lua that was returned in first.lua

ah, so complicated)

so, i cant post my code, but i can give an example of what needed

in main.lua:
[lua]local first = require(“first.lua”)

local obj = first.new{name = “image.png”}[/lua]

in first.lua:
[lua]module(…, package.seeall)

function new(params)
local second = require(“second”)
local name = params.name
local image = display.newImage(name)
local function touch()

local 2image = second.new{name = “image2.png”}
end

image:addEventListener(“touch”, touch)
return image
end[/lua]

in second.lua:
[lua]module(…, package.seeall)

function new(params)

local name = params.name
local image2 = display.newImage(name)

function destroy()
image2:removeSelf() – or something like that
end

return image2
end[/lua]

question is: how to call function destroy from second.lua in main.lua with another function? [import]uid: 16142 topic_id: 15888 reply_id: 58767[/import]

Er… that IS complicated! :smiley: I do not know why you are opting for such a round about method… but you’ll obviously have your reasons… So…

A Global variable for the object maybe? Instead of returning the object from each module,you call the module for operations and update the global variable from each module.

Dunno if it would help your cause though! :slight_smile:
[import]uid: 64174 topic_id: 15888 reply_id: 58771[/import]

thanks for suggestion, but i have no idea how to implement it))
i know its complicated, but i just wanted to make coding game easier, and it became harder) [import]uid: 16142 topic_id: 15888 reply_id: 58772[/import]