Marking Io objects so C++ addon can recognize them as belonging to it?

View: New views
2 Messages — Rating Filter:   Alert me  

Marking Io objects so C++ addon can recognize them as belonging to it?

by dennisf486 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

For my C++ to Io binding library, when I get a method call come in from Io, and I have a bunch of Io objects as arguments, some of them will be native Io objects like Numbers and Strings, and other ones will actually wrap C++ objects that the addon previously packaged up.  The data pointer of those 2nd type of objects should then point to a valid C++ object that I can cast to what I want, but how can I reliably tell the difference between objects I made and native Io objects?

I'm thinking the "tag" string could be used for this purpose - is that what "tag" is for?  Can the tag also tell me when it is a Number or String?  Is there an Io C-api macro I should use like "IS_IONUMBER" or "IS_IOSEQUENCE"?

Would it be better to use the protos list to mark the objects?  I could make every Io object I return that wraps a C++ object inherit from a certain proto, and check the protos list for that one.  Perhaps I could even attach a specific method to that proto like "Get_C++_Obj_Ptr" and use that method instead of accessing the data element directly, but can I re-enter the Io VM to call that proto's method and pop back out again to finish what I need to do with the C++ object it returns?

For that matter, say I want to check if an argument I receive is a Number or a String, is it better to check the tag or check if Number or String is a proto of the object?


Re: Marking Io objects so C++ addon can recognize them as belonging to it?

by Steve Dekorte :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 2009-09-14, at 2:38 PM, dennisf486 wrote:
> For my C++ to Io binding library, when I get a method call come in  
> from Io, and I have a bunch of Io objects as arguments, some of them  
> will be native Io objects like Numbers and Strings, and other ones  
> will actually wrap C++ objects that the addon previously packaged  
> up.  The data pointer of those 2nd type of objects should then point  
> to a valid C++ object that I can cast to what I want, but how can I  
> reliably tell the difference between objects I made and native Io  
> objects?

Hi Dennis,

You can test for primitive types using the IOOBJECT_ISTYPE() macro.  
Example:

        IOOBJECT_ISTYPE(self, Seq)

> I'm thinking the "tag" string could be used for this purpose - is  
> that what "tag" is for?  Can the tag also tell me when it is a  
> Number or String?  Is there an Io C-api macro I should use like  
> "IS_IONUMBER" or "IS_IOSEQUENCE"?

Yes, the tag contains the primitive type info. There are also  
convenience macros like:

        ISNUMBER(anObject)
        ISSEQ(anObject)
        ISMESSAGE(anObject)

etc.

Hope this helps,
Steve