Hey,

I was messing around with typemaps and I came up with the following 
code, which seems to work with Inline 0.43:

-----------------------------------------------
TYPEMAP
NN *                    WRAPPED_C_OBJECT

INPUT
WRAPPED_C_OBJECT
         $var = (($type)SvIV(SvRV($arg)))

OUTPUT
WRAPPED_C_OBJECT
         /* Use a block so I can declare variables here */
         {
           SV *container, *obj;
           container = newSViv(0);
           obj = newSVrv(container, class);
           sv_setiv(obj, (IV)$var);
           SvREADONLY_on(obj);
           $arg = container;
         }
-----------------------------------------------

This code is taken from the Inline::C-Cookbook, with one change - 
there's a 'class' variable here that's completely undeclared.  The only 
reason it works is that (so far) each function that returns a NN* is a 
constructor function, called like "AI::NodeLib"->new(), and I have 
declared that function in C with something like this:

   NN *new (char *class) {
      ...
   }

So if you consider the wrapper function Inline will make 
(XS_AI__NodeLib_new), you'll note that the typemap code will have access 
to the 'class' variable.

I guess my question is, can I count on this behavior, or is there a 
better way to accomplish what I'm trying to do?  This way results in 
some pretty slick Inlined code with a minimum of XS junk, but I feel 
like I'm abusing the concept of the typemap a little bit - it's not just 
performing a translation of one thing to another, instead it's using 
some external data that just happens to be there.

  -Ken

Reply via email to