View · Search · Index
No registered users in community xowiki
in last 10 minutes

[Xotcl] Calling object

From: Kristoffer Lawson <setok_at_fishpool.com>
Date: Fri, 9 Jul 2010 17:11:10 +0300

While XOTcl has a way to ask to query the object that is calling the current procedure, there does not seem to be a way to find out which object was 'previous' on the stack. I'll illustrate:

Class C

C instproc hello {} {
        puts "Hello, [self callingobject]"
}

C instproc do {} {
        my hello
}


Now if I call [hello] from another object, I will get the object which called [hello]. Of course, if that object calls [do] instead of [hello], then [self callingobject] will end up being the same as [self]. [uplevel] doesn't help here as [self callingobject] will always return the same, whatever stack level I call it from (is this a bug or intentional?). Basically there is no way to check "caller of caller" or, indeed, the "original caller" — ie. the object before [self] which initiated the process.

The reason I want to do this is that I have an access control system which calls something like [checkPermissions]. [checkPermissions] should just return and do nothing if the original calling object is equal to [self]. Now I end up having to passs [checkPermissions] a parameter with [self callingobject].

I guess I could also do this with a filter but that might be overkill for something so simple.

-- 
Kristoffer Lawson, Co-Founder, Scred // http://www.scred.com/