Leopold Toetsch wrote:


On Oct 30, 2005, at 1:54, Nick Glencross wrote:

Quick question...

I've been looking through inter_run and extend to see how to pass arguments to a parrot method/function from C, but all the prototypes that I've seen have '...' or 'va_list' to accept the arguments.

If I don't know what the arguments or their respective types are at compile time, what function is best for me?


There are 2 cases here:
1) you know the amount of args
2) you don't

In both cases you can use Parrot_runops_fromc_args() with a signature of "vPPP" or "vP" respectively. If you expect a return value change the initial 'v' to 'P'. For the second case you have to put all args into a *PMCArray.


Hmmm. still don't think that's what I want. Obviously this is in the context of the NCI callback stuff that I'm looking into -- no surprises there.

The callback is written by the parrot coder, so let's say we have this:

.sub _call_back
   .param int a
   .param int b

   print "Hello world!\n"
   print a
   print " "
   print b
   print_newline

.end

The callback 'trampoline' code in C needs to call this, but doesn't know at compile time what to expect, but it does have the parrot signature (e.g. vii) and access to all the values to be passed on, albeit only by looping over them.

For case 1) I have the number of args and the signature, but don't believe that I can convert the arguments into a form that I can pass to any of the existing function calls.

In case 2), which I've just tried, I think that I'm right in saying that the *PMCArray will arrive as the first argument of _call_back, which will automagically convert to an int, being its length.

What think is needed is a routine which will dereference the array and pass its contents as arg1, arg2, ...

Thanks for your help Leo! As you can imagine this is the last step to having something to show for callbacks!

Nick

Reply via email to