[chuck-users] determining the type of an Object in code

mike clemow gelfmuse at gmail.com
Wed Feb 11 00:42:54 EST 2009


Yes, like instanceOf() in other languages.

First off, I think that makes perfect sense, but I also don't have the
slightest clue how to implement it.  ;-)

Taking a class per se as an argument would necessitate looking that
token up in some list of classes available at runtime, no?  Also, it
seems that these things would have to be defined separately for UGen
and Object--as far as I can tell.  My C++ skills are next-to-absent,
to be honest.

In the meantime, taking a string representation of a class, like
"Object", for an argument would be much easier to implement (for me,
anyway).  We could do this just to prototype the feature, see if it's
useful, etc.

myObject.isA( "Object" )

Could return true or false.  This I think we could have up and running
quickly to try it out.  Perhaps then someone smarter than me would be
interested in looking into making it so that it could be done without
the quotes (i.e. as a class and not a string), which, I assume, would
be safer.

-Mike

On Wed, Feb 11, 2009 at 12:25 AM, Kassen <signal.automatique at gmail.com> wrote:
>
>
> 2009/2/11 mike clemow <gelfmuse at gmail.com>
>>
>> If getType() was stubbed out, then my guess is that we shouldn't mess
>> with it.  Perhaps we should change the name of this method to
>> something else.  getClass() maybe...
>
> How about ".isA( type)" that would return true or false ?
>
> I'm suggesting that because some object may be
> *a Object
> *a UGen
> *a STKInstrument
> *a Sitar
>
> ...all at the same time. So; "my_sitar" would return true for all those and
> this;
>
> if ( my_sitar.isA( Event ) ) do.someThing();
>
> ...wouldn't work.
>
> Does that make sense to you?
>
> Kas.
>
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>
>



-- 
http://michaelclemow.com
http://semiotech.org


More information about the chuck-users mailing list