Io C API questions/frustrations

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

Io C API questions/frustrations

by dennisf486 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It seems like the Io C API steers you very strongly into certain mold for how you should write your addons.  The API is chock full of functions like "xxx_SeqArgAt" and "xxx_IntArgAt" and so on.  The idea seems to be that you have a C function which takes certain args, and you know what types you expect before you start, and you only accept that exact format.

I find it strange that a language as dynamic as Io would take such an inflexible approach in its C API.  I mean, in the Io language itself you can write a function which accepts any type of args and does something reasonable.  Yet the choice of functions provided in the Io C API makes it very unobvious how write an addon in C which treats its arguments dynamically.

For my C++ binding library I have one generic C-function target that can wrap many different C++ functions with different signatures.  So I want to be able to just get a plain "argAt(pos)" without saying ahead of time whether I expect a number or a string, etc.  I need to be able to do this because the library is capable of doing automatic conversions, so in theory I could accept more than one type of thing for any given argument and might be able to find a user defined conversion that turns it into the thing the bound method needs.

I need either (best case) a generic ArgAt function, or (can make do with extra work) a way to examine the tag of an argument before actually converting the argument.

Some questions:

- Why is the function IoMessage_locals_valueOrEvalArgAt() not defined?  That seemed to be exactly what I need and then it turns out it's declared but never implemented!

- I'm assuming IoMessage_locals_valueArgAt() is not going to work correctly for things that aren't values.  Could you explain what things those might be?  I'm assuming that would be when you pass the result of a method as an argument, but the method hasn't be called/activated yet?

- Can I just eval all my args and then get the result with _valueArgAt()?  What function do I use to trigger evaluation of the arg, and how do I even get the Io object to do it on?  I saw some .io files that call evalArgAt, but I don't see the equivalent function in the C API.


Re: Io C API questions/frustrations

by Steve Dekorte :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 2009-10-03, at 5:04 PM, dennisf486 wrote:
> For my C++ binding library I have one generic C-function target that  
> can wrap many different C++ functions with different signatures.  So  
> I want to be able to just get a plain "argAt(pos)" without saying  
> ahead of time whether I expect a number or a string, etc.  I need to  
> be able to do this because the library is capable of doing automatic  
> conversions, s

Hi Dennis,

I think:
       
        IoObject *v = IoMessage_locals_valueArgAt_(m, locals, argNumber)

should do what you need.