Lua Module Function Critiqued

Hi guys!

Shaun here,

It's possible you've seen my name float around, I've done a lot of reading, I've done a tiny bit of replying. This is my first post.

Lately I've done a lot of reading on things like the Director Class, the OOP template in the code exchange, and just on modules and groups in general. With the documentation in the api on modules being next to nothing I turned to the net at large for some answers.

In my readings I came across this:

http://lua-users.org/wiki/LuaModuleFunctionCritiqued

In the post the author details how modules work typically in lua, and the problems they can cause without even listing an error. Toward the bottom (last example before comments) he offers up an alternative that makes a lot of sense.

I was curious what your takes are, considering I took very little C in college and this is only my second scripting language I'm not as experienced as some in the Ansca community.

With that, have a read and let me know what your impressions are. At the very least I thought the community should know there's an alternative to using modules. When doing this like the director class, it seems like it could simply things greatly and reduce the lines of code.

Shaun
Zombie Alligator Games

Umm that'll take a few reads !! But his whole original approach is different

I would do

1
2
3
4
5
-- hello/world.lua
module(..., package.seeall)
local function test(n) print(n) end
function test1() test(123) end
function test2() test1(); test1() end

No problem, perhaps I can provide a simplified example:

Let's say you're making a splash screen. So you'll make a lua file called splashScreen.lua to contain it. Normally using module you would write that like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
-- splashScreen.lua
 
module (..., package.seeall)
 
function play ()
     function splashProcess (event)
          if event.completed then
               print ("I like tacos!")
          else
               print ("impossible splash screen error has occurred!")
          end
     end
     local background = display.newImage ("splashBackground.png", -125, 125)
     local splashSound = audio.loadSound ("bleah.wav")
     local splashChannel = audio.play (splashSound, {onComplete=splashProcess})
end
views:1546 update:2011/10/6 9:28:12
corona forums © 2003-2011