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 7398505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:52:41+00:00 2026-05-29T03:52:41+00:00

My app have some events, each event can have some actions. These actions is

  • 0

My app have some events, each event can have some actions. These actions is implemented in C++. I want to expose those core functions to python and use python to write the action. The advantage is I can modify actions without recompile. For example:

CppClass o;

// --- this is a action----
o.f1();
o.f2();
// ------------------------

use python to script the action:

def action1(o):
    o.f1()
    o.f2()

In c++, use interpreter to run this script, find action1 and call it with a PyObject which convert from c++ object. Actually, I have not expose f1() & f2() to python, I just use python to regroup the definition of action, all function is running by c++ binary code. Notice that I have not to give a definition of f1() & f2() in python.

The problem is: how I expose global functions? such as:

def action2():
    gf1()
    gf2()

boost::python can expose function, but it is different, it need compile a DLL file and the main() is belong to python script. Of course I can make global functions to be a class static member, but I just want to know. Notice that I HAVE TO give a definition of gf1() & gf2() in python.

Jython can do this easily: just import Xxx in python code and call Xxx.gf1() is ok. But in cython, how I define gf1() in python? This is a kind of extension, but extension requires Xxx be compiled ahead. It seems only way is make gf() into a class?

  • 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-29T03:52:42+00:00Added an answer on May 29, 2026 at 3:52 am

    Solved. boost::python’s doc is really poor…

    For example: expose function

    void ff(int x, int y)
    {
        std::cout<<x<<" "<<y<<std::endl;
    }
    

    to python:

    import hello
    def foo(x, y)
        hello.ff(x, y)
    

    you need to expose it as a module:

    BOOST_PYTHON_MODULE(hello)
    {
        boost::python::def("ff", ff, boost::python::arg("x"), boost::python::arg("y"));
    }
    

    But this still is not a ‘global function’, so expose it to python’s main scope:

    BOOST_PYTHON_MODULE(__main__)
    {
        boost::python::def("ff", ff, boost::python::arg("x"), boost::python::arg("y"));
    }
    

    then you can write:

    def foo(x, y)
       ff(x, y)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some java-app, and i want to establish a connection to some https
Given and coredata based app using an Indexcard metaphor. Each Indexcard can optionally have
in my app I have some text.setTextColor(Color.GRAY) . Now I would like to use
I am creating a greeting card app.I have some existing templates and i also
I have created a wildcard App ID and have some questions about bundle ID
I have question. I have some app on facebook and getting this error Fatal
i have some WinForms app (Framework to develop some simple apps), written in C#.
i have some WinForms app (Framework to develop some simple apps), written in C#.
I have some settings in my app.config which I intend to be 'global' -
I have some classes in my app that don't require an ID to be

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.