Are there any other ways to call instance methods, other than instance:method() ? [import]uid: 4596 topic_id: 8154 reply_id: 308154[/import]
why? [import]uid: 12108 topic_id: 8154 reply_id: 29046[/import]
Curiosity, and getting to know more about lua. [import]uid: 4596 topic_id: 8154 reply_id: 29050[/import]
ok without getting into modules and metatables for now
[lua]local function makeStuff(color)
local stuff = {}
stuff.color = color
stuff.greet = function()
print(“greetings, so you want me to be “…stuff.color )
print(“well you asked for “…color…”, so i guess so”)
print(”—”)
end
stuff.hello = function(self)
print("hello, i am "…tostring(self))
print("you asked me to be "…color)
print(“so my color is “…self.color)
print(”—”)
end
function stuff:hi()
print("hi, i am "…tostring(self))
print("you asked me to be "…color)
print(“so my color is “…self.color)
print(”—”)
end
return stuff
end
local redstuff=makeStuff(“red”)
redstuff.greet()
–redstuff.hello() – will fail, self doesnt exist
redstuff.hello(redstuff)
redstuff:hello()
–redstuff.hi() – will fail, self doesnt exist
redstuff.hi(redstuff)
redstuff:hi() – this is the same as the line before it
local bluestuff=makeStuff(“blue”)
bluestuff.greet()
–bluestuff.hello() – fails
bluestuff.hello(bluestuff)
bluestuff:hello() – this is the same as the line before it
–bluestuff.hi() – fails
bluestuff.hi(bluestuff)
bluestuff:hi() – this is the same as the line before it[/lua]
note you can’t define both
[lua]stuff.hi = function(self)[/lua]
and
[lua]function stuff:hi()[/lua]
they are the same thing! the second will overwrite the first [import]uid: 6645 topic_id: 8154 reply_id: 29073[/import]
The point he’s getting at is that the colon is just syntactic sugar in Lua for using “self” as the first parameter. You can also write down “self” manually and it’ll do the same thing. [import]uid: 12108 topic_id: 8154 reply_id: 29143[/import]
true jhocking, i was.
but who knows what “syntactic sugar” means 
thanks
j
[import]uid: 6645 topic_id: 8154 reply_id: 29147[/import]
Good stuff. Thanks guys. Is there any other way to silently inject arguments similar to how the : operator does with self? [import]uid: 4596 topic_id: 8154 reply_id: 29195[/import]
well you’ve got these, which are useful…
[lua]function someFunction(transitionedObject)
print(transitionedObject.name) – Me!
end
someObject.name = “Me!”
transition.to(someObject, time=1500, alpha=0, onComplete=someFunction } )[/lua]
and also
[lua]function someOtherFunction(event)
local theTimer = event.source
print(theTimer.someVariable) – “hello!”
end
local someTimer = timer.performWithDelay(100, someOtherFunction)
someTimer.someVariable = “hello!”[/lua] [import]uid: 6645 topic_id: 8154 reply_id: 29209[/import]
Or… you can use a closure over an object reference to a table that is passed as a function parameter, like the bug in ui.lua that I pointed out at:
http://developer.anscamobile.com/forum/2011/03/06/serious-bug-uilua-v15
which I seriously hope nobody will see as a possible cool feature to change some object state thru a backdoor 
-FrankS.
PS. Bug is still there and never heard any reaction…
[import]uid: 8093 topic_id: 8154 reply_id: 29215[/import]
That is an interesting bug, but I would hardly call that a serious bug. I mean, that entire problem goes away if you simply nil out params after using it. [import]uid: 12108 topic_id: 8154 reply_id: 29223[/import]
Indeed - nil’ing out of params would not make this bug show up… but only if you know about it…
But I was reusing params to create a number of different buttons with similar properties and only changing those that were different - seemed like a good strategy at the time.
Then this bug made me waste a good day because it’s effects are obscure, sometimes show up, and depend on execution order - that makes it serious and nasty.
It also shows a pitfall about the use of closures that probably few realize or understand - should be part of best practices to copy your structures that you want to use in your closure.
So in short… I vehemently disagree and believe this is a serious bug and it’s part of all the demo code of Corona as an example for us to use… some example 
-FrankS.
[import]uid: 8093 topic_id: 8154 reply_id: 29228[/import]
Actually, it just occurred to me that even nil’ing params isn’t able to mask-out the effect of the bug…
params.textColor is an other object/table that is copied in ui.lua by reference in the closure, which means that if I would reuse that color-table in the newly assigned params, and change for example only the R-value for the next button, I would still observe the side-effect in the previous button even though I did a params=nil in between.
A bug with side-effects thru 2 indirections… enough to make your head spin and to pull out the few hairs that I have left… that is more than “interesting”… that is pure nasty 
-FrankS.
[import]uid: 8093 topic_id: 8154 reply_id: 29248[/import]
it’s part of all the demo code of Corona as an example for us to use
huh, you hadn’t mentioned that part, and a mistaken example is pretty concerning. Incorrect documentation is worse than no documentation. I haven’t seen that particular demo code since I’ve never encountered this bug myself, which demo is that? Ansca’s documentation is a little off in many places (eg. their button samples use an old version of ui.lua)
As for the seriousness of your bug, well sorry to be harsh but if things work fine when you simply word the code a little differently then that’s not a serious bug. That is an inconvenience that ought to be documented. I too have certainly felt boiling anger over inconveniences that wasted my time, but I don’t conclude that every problem I have is a serious bug. You need have a sense of perspective; if you’re the only one reporting the problem, then it’s only important to you.
Incidentally, I should clarify that the only reason I’m arguing with you is simply because titling your thread “Serious bug” leaves a bad taste in my mouth. I don’t disagree that you should report the issue, I just don’t like when people use misleading hyperbole. And it’s nothing personal, mostly just because I’m annoyed with how the “Showstopping Bugs” forum got abused into pointlessness. [import]uid: 12108 topic_id: 8154 reply_id: 29252[/import]
ui.lua 1.5 - latest and greatest as far as I know.
(ignoring patronizing part of your reply)
-FrankS.
[import]uid: 8093 topic_id: 8154 reply_id: 29273[/import]