Reputation: 763
Although there is a documentation available, I got more confused, rather then enlightened. Let's consider an example:
I have a myObject instance, which has myMethod method and I call it from the lobby:
myObject myMethod
In this method's body following is done:
myObject1 anotherMethod //1
msg := message(anotherMethod)
myObject2 do(msg) //2
myObject3 doMessage(msg) //3
So, could anyone explain me differences between 1 2 and 3?
Who is the actual caller for these cases? The locals object of the method, the method object or myObject? Is there a difference between sender and caller (I suppose there is one in case of doMessage, where sender is the locals object of the myMethod, but the "caller" is myObject3)
Upvotes: 1
Views: 201
Reputation: 20236
Alright, so in order:
anotherMethod
is received by the instance named myObject
. This is done in the calling context (probably the Lobby, unless wrapped inside another do()
do()
introduces a new scope, and does nothing with the calling scope. That is to say, you can't reference anything in the calling scope inside a do()
unless it happens to be in the Protos hierarchy or introduced inside the do()
. do()
also takes a message tree, and so what you're doing is effectively sending message(msg)
to be evaluated inside the context of myObject
which doesn't make much sense since msg
first off can't be found due to the scope not being available, and even if it was, wouldn't make a lot of sense. Generally, you want to do something like: msg doInContext(myObject)
if you find yourself desiring to write myObject do(msg)
.Upvotes: 2