Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

renaming all "self" to simply "o"

  • Loading branch information...
commit 6e1f0bcbc42890c3bdd7443eababcf4cb58cd33c 1 parent 10309fb
@johnlindquist authored
Showing with 30 additions and 13 deletions.
  1. +1 −1  luna/Luna.lua
  2. +6 −5 luna/Model.lua
  3. +23 −7 luna/View.lua
View
2  luna/Luna.lua
@@ -27,7 +27,7 @@ local function createMessenger()
end
messenger.addEventListener = function(self, messageName, listener)
--- print("addEventListener: ", messageName, listener)
+ print("addEventListener: ", messageName, listener)
if listener == nil then listener = self end
receivers[messageName] = receivers[messageName] or {}
View
11 luna/Model.lua
@@ -8,7 +8,7 @@ return function()
function o:setCurrentTime(value)
currentTime = value
- self:dispatchEvent({name = "timeChange", data = currentTime})
+ o:dispatchEvent({name = "timeChange", data = currentTime})
end
local someTable = {}
@@ -17,14 +17,15 @@ return function()
end
function o:timer()
- self:setCurrentTime(currentTime + 1)
+ o:setCurrentTime(currentTime + 1)
end
function o:init(startingTime)
- self:setCurrentTime(startingTime)
+ o:setCurrentTime(startingTime)
+ --If you don't include the second param, it will default to "self" (which is also "o" in this case)
--example of a "table listener"
- self:addEventListener("scoreTap", someTable) --If you don't include the second param, it will default to "self"
- timer.performWithDelay(1000, self, 0)
+ o:addEventListener("scoreTap", someTable)
+ timer.performWithDelay(1000, o, 0)
end
return o
View
30 luna/View.lua
@@ -7,18 +7,34 @@ return function()
end
+ -- This is invoked if you use self:addEventListener("timeChange")
local function onTimeChanged(event)
scoreDisplay.text = event.data
end
+ --[[
+ Because "self" and "o" are the same in the "init" function,
+ "o:timeChange" is invoked if you use one of these options:
+ self:addEventListener("timeChange") --defaults to "self"
+ self:addEventListener("timeChange", self)
+ o:addEventListener("timeChange")
+ o:addEventListener("timeChange", o)
+ self:addEventListener("timeChange", o)
+ o:addEventListener("timeChange", self)
+ ]]
+
+ function o:timeChange(event)
+ scoreDisplay.text = event.data
+ end
+
function o:tap(event)
- --send a "tap" to anyone listening by receive("tap")
- self:dispatchEvent({ name = "scoreTap", data = 0 })
+ --send a "scoreTap" to anyone listening by receive("scoreTap")
+ o:dispatchEvent({ name = "scoreTap", data = 0 })
- if self:hasEventListener("timeChange", onTimeChanged) then
- self:removeEventListener("timeChange", onTimeChanged)
+ if o:hasEventListener("timeChange", onTimeChanged) then
+ o:removeEventListener("timeChange", onTimeChanged)
else
- self:addEventListener("timeChange", onTimeChanged)
+ o:addEventListener("timeChange", onTimeChanged)
end
end
@@ -27,10 +43,10 @@ return function()
scoreDisplay = display.newText("Woo haa!", 0, 0, native.systemFont, 16)
scoreDisplay:setTextColor(255, 255, 255)
- scoreDisplay:addEventListener("tap", self)
+ scoreDisplay:addEventListener("tap", o)
--example of a "function listener"
- self:addEventListener("timeChange", onTimeChanged)
+ o:addEventListener("timeChange", onTimeChanged)
end
return o
Please sign in to comment.
Something went wrong with that request. Please try again.