I want to embed Perl in a c++ application and am looking for a method to call into c++ from perl via newXS(). Apart from the function pointer I need the associate a custom pointer to the CV created by newXS(). The pointer contains a C++ context. I dont want to use globals for this. Is there a common way to do this?
On a wider scope the question is maybe weather there is the possibility to add a closure to the CV created by newXS() and how to reference it when the c function is called that was registered with it. CvPADLIST() would seem the perfect place, however for XSubs it seems to be invalid to use when PERL_IMPLICIT_CONTEXT is set (comment in the beginning of perl's pad.c. Can it maybe be ignored?). Is there some other place I can put CV local data?
sub make_closure { my $ctx = new_context(); return sub { xs_func($ctx, @_) }; }
– Bedwarmereval
... That is one possibility. Was looking at PERL_MAGIC_ext, maybe another way... – Hetman