Test if an object is of a given class (from the VM)

Javier Lanatta javier at lanatta.com.ar
Mon Dec 8 15:44:54 UTC 2003


Well this code does work; anyway I have no idea why the previous one
didn't... 

arrayOfClasses _ self splObj: ArrayOfClasses.
arrayOfClassesSize _ self stSizeOf: arrayOfClasses.
i _ 0.
rcvrClass _ self fetchClassOf: rcvr.
[i<arrayOfClassesSize] whileTrue:
[
	aClass _ self fetchPointer: i ofObject: arrayOfClasses.
	(rcvrClass == aClass) ifTrue: [found _ true].
	i _ i + 1.
].

Regards, 
	Javier

> -----Original Message-----
> From: squeak-dev-bounces at lists.squeakfoundation.org [mailto:squeak-dev-
> bounces at lists.squeakfoundation.org] On Behalf Of Javier Lanatta
> Sent: Monday, December 08, 2003 11:42 AM
> To: squeak-dev at lists.squeakfoundation.org
> Subject: Test if an object is of a given class (from the VM)
> 
> Hello,
> 	I'm trying to access an array of classes from the VM to test if an
> object is of a class present on this array. The array is defined in the
> specialObjectsArray and it was created using:
> 
> Smalltalk specialObjectsArray at: 58 put: (Array with: TestClass with:
> Testclass2)
> 
> I'm using the following code (from the VM) to test if the "rcvr" is of a
> given class present on the array:
> 
> 
> arrayOfClasses _ self splObj: ArrayOfClasses.
> arrayOfClassesSize _ self stSizeOf:arrayOfClasses.
> i _ 0.
> [i<arrayOfClassesSize] whileTrue:
> [
> 	aClass _ self fetchPointer: i ofObject: arrayOfClasses.
> 	self assertClassOf: rcvr is: aClass.
> 	successFlag ifTrue: [self print:'Class found!';cr.found _ true].
> 	i _ i + 1.
> ].
> 
> The problem is that this code only works for the first item of the
> array...
> That is if the object is a TestClass it works fine, but if the object is a
> TestClass2 it does not work. Any ideas?
> 
> Regards,
> 	Javier
> 





More information about the Squeak-dev mailing list