Friday, October 26, 2012

Corona SDK and good architectural practices


John has created an architecture document using UML following good Agile practices.  There are factories, components and other well laid out logical blocks that should allow us to parse out tasks, and develop in an iterative way.

Now the question is, will Lua/Corona SDK support such a way of doing this kind of work.  After all, it is a scripting language, using a main.lua file that controls the code that gets run.

After doing some looking around for demos and examples of displaying text to users I found that yes, indeed Lua does allow the ability to create discreet Lua modules, which can be treated as if they were classes.

The module sits in the same directory as the main.lua file; a variable is named and pointed to the module such as:

·         local director = require("director")

·         ui = require( "ui" )

Lua variables are global by default; so ui is now used throughout the application.  The local keyword keeps the director variable scope limited to the current code module.

Now we can create code modules and use already code modules easily, without creating spaghetti bowls of code in our common main.lua file.  And keep within the spirit of John’s architectural plan to boot.

No comments:

Post a Comment