Coder Social home page Coder Social logo

Comments (1)

fanchy avatar fanchy commented on May 27, 2024

now ffpython has supported that case, i have update the ffpython.h and example.cpp, you can see the example.cpp how to call pyclass method. By the way, ffpython now can call python lamda function.
But you should pay more attention when using that api, because you should call Py_DECREF when you don't need the reference of the python handle.
example python code:

class pyclass_t:
    def __init__(self):
        print('pyclass_t init....')
    def sayHi(self, a1, a2):
        print('sayHi..', a1, a2)
def test_cpp_obj_return_py_obj():
    return pyclass_t()
def test_cpp_obj_return_py_lambda():
    def test_lambda(a1):
        print('test_lambda....', a1)
    return test_lambda

example c++ code:

void test_py_class_lambda(ffpython_t& ffpython)
{
    PyObject* pobj = ffpython.call<PyObject*>("fftest", "test_cpp_obj_return_py_obj");
    ffpython.obj_call<void>(pobj, "sayHi", 1, string("soNice"));

    PyObject* pFunc= ffpython.call<PyObject*>("fftest", "test_cpp_obj_return_py_lambda");
    ffpython.call_lambda<void>(pFunc, 112233);

    Py_DECREF(pFunc);
    Py_DECREF(pobj);

}

from ffpython.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.