[Xotcl] Calling object

Kristoffer Lawson setok at fishpool.com
Fri Jul 9 16:11:10 CEST 2010


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/



More information about the Xotcl mailing list