Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3307972
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:28:05+00:00 2026-05-17T21:28:05+00:00

Ok, this is a very interesting question and there may not be any easy

  • 0

Ok, this is a very interesting question and there may not be any easy way to do this but figured I would throw this out there before deciding that modifying Perl is my underlying answer.

So I’ve got a C application that calls Perl scripts in an embedded fashion. This all works fine and dandy and it’s pretty awesome that I can pass information in and get information back out. HOWEVER, now onto my next conquest; I need to allow my embedded script(s) to be able to call some functions within the C application that ORIGINALLY CALLED IT.

This is important because XSUB would require it to be an external library; but I don’t want it to be an external library I want it to be a direct call to the C function(s). Now maybe this can be done via XSUB and I’ve just been reading and understanding it wrong.

Application -(run)-> Perl

Application <-(function_x())- Perl

Application -(returnfunction_x)-> Perl

The reason this cannot be an external library is because I am relying on data that is solely created/stored within the application.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:28:05+00:00Added an answer on May 17, 2026 at 9:28 pm

    XSUBs actually don’t require there to be an external library. They merely provide the ability to call to a c function from perl space, and provide some convenience in mapping the calling conventions between C and Perl.

    All you need to do is register XSUBs you compiled into the embedding application with the perl interpreter you’re embedding.

    #include "XSUB.h"
    
    XS(XS_some_func);
    XS(XS_some_func)
    {
        dXSARGS;
        char *str_from_perl, *str_from_c;
    
        /* get SV*s from the stack usign ST(x) and friends, do stuff to them */
        str_from_perl = SvPV_nolen(ST(0));
    
        /* do your c thing calling back to your application, or whatever */
        str_from_c = some_c_func(str_from_perl);
    
        /* pack up the c retval into an sv again and return it on the stack */
        mXPUSHp(c_str);
        XSRETURN(1);
    }
    
    /* register the above XSUB with the perl interpreter after creating it */
    newXS("Some::Perl::function", XS_some_func, __FILE__);
    

    When embedding perl, this sort of thing is usually done in the xs_init function you pass to parse_perl.

    EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
    
    static void
    xs_init (pTHX)
    {
        newXS("Some::Perl::function", XS_some_func, __FILE__);
        /* possibly also boot DynaLoader and friends. perlembed has more
         * details on this, and ExtUtils::Embed helps as well. */
        newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
    }
    
    perl_parse(my_perl, xs_init, argc, my_argv, NULL);
    

    After that you’ll be able to call to the XSUB as Some::Perl::function from perl space, and that XSUB in turn is free to call back to your application in any way it wants to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm generally not a fan of microbenchmarks. But this one has a very interesting
there's this interesting problem i can not solve myself. I will be very glad,
There was a very interesting discussion on LosTechies regarding AutoMapper(an argument for/against 2-way mapping).
I found this question very interesting : Programmatic Bot Detection I have a very
I have question, maybe it's not critical in programming, but to me it's very
I'm using this very handy plugin to sort elements. But comparing elements on a
Firstly, I realise that this is a very similar question to this one: Which
I must apologize if this is a duplicate question, but I can't seem to
This question is inevitably subjective, but I will ask anyway. I'm a PC. I've
I have a very interesting LINQ question. I have a document, that I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.