Works for me (ActiveState Perl 10.1 on Windoze).

Did you miss the syntax error in your code (missing ; after until)? Try use warnings;

Here is my C:
#include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" #include "const-c.inc" MODULE = MyModule PACKAGE = MyModule INCLUDE: const-xs.inc int RegisterCB (SV *SubRef) CODE: ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(sv_2mortal(newSVpv("Some event",0))); XPUSHs(sv_2mortal(newSVpv("Some pdata",0))); PUTBACK; call_sv(SubRef, G_DISCARD); FREETMPS; LEAVE; RETVAL = 1; OUTPUT: RETVAL
Here is the Perl (its a long time since I didn't use strict;):
use MyModule; use warnings; #shared scalar $cb_done = 0; #This cb would be invoked by the cloned interpreter in the #C library. This works fine. sub cb_one { ($event, $pdata) = @_; #This line is printed. print "event : ", $event, "\n"; $cb_done = 1; } $status = MyModule::RegisterCB(\&main::cb_one); do { sleep (5); } until ($cb_done == 1); #This line is printed as $cb_done becomes 1 #in the main of the perl script print "CB was invoked : $cb_done\n";
and here is the output:
C:\gash\MyModule>test.pl Name "main::pdata" used only once: possible typo at C:\gash\MyModule\t +est.pl line 11. Name "main::status" used only once: possible typo at C:\gash\MyModule\ +test.pl line 17. event : Some event CB was invoked : 1

Update: original code was not passing parameters to the callback.
Update 2: I hadn't freed the temporaries and closed the scope

In reply to Re: Extending & Embedding Perl simultaneously: How to share a scalar between perl callback sub and main body? by cdarke
in thread Extending & Embedding Perl simultaneously: How to share a scalar between perl callback sub and main body? by perlmonk1729

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.