Hi,
I’ve read on a blog post (http://www.coronalabs.com/blog/2011/09/05/a-better-approach-to-external-modules/) here that module is considered “bad” because it makes you use global declarations.
I’m new to Corona so I’m yet to hit with a problem with my game, memory-wise or anything, but my previous game dev experience tells me to be aware of such thing.
So I was reading another blog post (yes I have more than 2Gb’s worth of open tabs in my browser …) regarding how to, at least one of the ways of, doing OOP in Lua/Corona that I stumbled upon this:
[lua]module (…, package.seeall)
function new()
local box = require(“BasicBox”).new()
function box:move()
self.rotation = math.random(360)
end
function box:setColor()
self:setFillColor(255, 0, 0)
end
return box
end[/lua]
And as that blog posts’ last line challenged us: “I want you to abolish the use of the module() function, while still reaping the benefits of modular coding!”, I was wondering how I can write that code in the same way that he did with it’s example, with defining a local table to store all references to functions/variables:
[lua]-- define a local table to store all references to functions/variables
local M = {}
– functions are now local:
local testFunction1 = function()
print( “Test 1” )
end
– assign a reference to the above local function
M.testFunction1 = testFunction1
local testFunction2 = function()
print( “Test 2” )
end
M.testFunction2 = testFunction2
local testFunction3 = function()
print( “Test 3” )
end
M.testFunction3 = testFunction3
– Finally, return the table to be used locally elsewhere
return M[/lua]
Thanks. [import]uid: 206803 topic_id: 34775 reply_id: 334775[/import]

[import]uid: 41884 topic_id: 34775 reply_id: 138353[/import]