Exposing Perl objects in C

[email protected] (JR Heisey) Wed, 04 Mar 2015 18:18:29 +0100
Newsgroups perl.xs
Message-ID <[email protected]>
Hi,

I have a collection of Perl objects in an application.
I want a C program to have access to the data in these objects.
The objects are implemented as a package

The C application wants an object handle with which it can make C 
function calls and pass the object handle.

I have limited experience writing to the PerlApi, etc. I was hoping that 
each perl SV has some unique identifier (UID). The goal is to retrieve 
the UID, pass it as an integer or void * so I don't need to manage my 
own list of Perl objects.

I realize I could create new SV * and increment the reference count.
I would then need to keep track of these SV pointers in order to clean 
them up later.

I would hoping I could use a UID to create temporary SV * objects, 
perform a data access then decrement the reference count.

void get_dataInt(FOO * foo, int * value)
{
   // abbreviated Perl stack stuff
   SV * pOjbect = newSV_VooDoo((someVooDooCast)foo); // a 32 bit value 
if I am lucky
   XPUSHs(sv_2mortal(pObject));
   PUTBACK;
   count = call_method("getData", G_EVAL | G_SCALAR);

   // error checking stuff
   *value = POPi;
}

Or something conceptually like that.

With out this I need to allocate my own C object with which to capture a 
reference to the underlying Perl objects.

Thanks,
J.R.