I have Perl/Tk application that draw polygons on a Tk::Canvas.  For speed
reasons,
I used Inline to create a C subroutine that computes various numbers and
calls
the Tk::Canvas::createPolygon method.

Following is the body of a loop written using XS macros:


for (/* stuff */) {
   ENTER;
   SAVETMPS;

   PUSHMARK(SP);

   XPUSHs(canvas_rv);         /* SV* to a Canvas object */
   XPUSHs(sv_2mortal(x1)));   /* coordinates on the canvas */
   XPUSHs(sv_2mortal(y1)));
   XPUSHs(sv_2mortal(x2)));
   XPUSHs(sv_2mortal(y2)));
   XPUSHs(sv_2mortal(x3)));
   XPUSHs(sv_2mortal(y3)));
   XPUSHs(sv_2mortal(newSVpv("-fill",  0))); /* arguments to the method (see
below) */
   XPUSHs(sv_2mortal(newSVpv(color,    0)));
   XPUSHs(sv_2mortal(newSVpv("-tags",  0)));
   XPUSHs(sv_2mortal(newSVpv("-eface", 0)));

   PUTBACK;

   call_method("createPolygon", G_VOID); /* call the
Tk::Canvas::createPolygon method */

   SPAGAIN;
   PUTBACK;
   FREETMPS;
   LEAVE;
}

I tried to rewrite the above code using Inline_Stack_* macros, and after
reading the
Inline documentation I figured this would work:

for (/* stuff */) {
   Inline_Stack_Vars;
   Inline_Stack_Reset;

   XPUSHs(canvas_rv);         /* SV* to a Canvas object */
   XPUSHs(sv_2mortal(x1)));   /* coordinates on the canvas */
   XPUSHs(sv_2mortal(y1)));
   XPUSHs(sv_2mortal(x2)));
   XPUSHs(sv_2mortal(y2)));
   XPUSHs(sv_2mortal(x3)));
   XPUSHs(sv_2mortal(y3)));
   XPUSHs(sv_2mortal(newSVpv("-fill",  0))); /* arguments to the method (see
below) */
   XPUSHs(sv_2mortal(newSVpv(color,    0)));
   XPUSHs(sv_2mortal(newSVpv("-tags",  0)));
   XPUSHs(sv_2mortal(newSVpv("-eface", 0)));

   PUTBACK;

   call_method("createPolygon", G_VOID); /* call the
Tk::Canvas::createPolygon method */

   Inline_Stack_Done;
}

However, when I run the above code it bombs with the following message:

   Tk::Error: Can't call method "createPolygon" without a package or object
reference at blib/lib/Cf/OutputNoteBook.pm line 4751.
    Cf::OutputNoteBook::draw_ef at blib/lib/Cf/OutputNoteBook.pm line 4751
    Cf::OutputNoteBook::calculate_output at blib/lib/Cf/OutputNoteBook.pm
line 4525
    Cf::OutputPage::__ANON__ at blib/lib/Cf/OutputPage.pm line 204
    Tk::After::once at
/release/lib/perl5/site_perl/5.6.1/IP30-irix/Tk/After.pm line 83
    [once,[{},after#577,100,once,[\&Cf::OutputPage::__ANON__]]]
    ("after" script)

Can anyone tell me how to rewrite my code properly using Inline_Stack_*
macros?

Thanks,

Brett


-- 
 Brett W. Denner                    Lockheed Martin Aeronautics Co.
 email: [EMAIL PROTECTED]     PO Box 748, MZ 9332
 phone: 817-935-1144                Fort Worth, TX 76101
 fax:   817-935-1212

Reply via email to