Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Calling A S60 Python Function From Symbian C++

DZone's Guide to

Calling A S60 Python Function From Symbian C++

·
Free Resource
Calls the Python function 'foo' in the module 'Bar'. 
A string value is passed to the Python function, and a string value is returned


    TInt retVal(KErrNone);

    // Create a Python interpreter
    CSPyInterpreter* it = CSPyInterpreter::NewInterpreterL();
    CleanupStack::PushL(it);

    // Save state of any current Python interpreter, and acquire the
    // interpreter lock
    PyEval_RestoreThread(PYTHON_TLS->thread_state);

    char *module_name = "Bar" ;
    char *foo = "foo" ;
    char *response = NULL ;

    TInt32 r_len = 0 ;

    PyObject *pModule = PyImport_ImportModule(module_name) ;

    if ( pModule != NULL )
    {
    LOG_WRITE_L("CSenPythonSession::loaded ServiceConnection");

    PyObject *module_dict = PyModule_GetDict(pModule);
    PyObject *expression = PyDict_GetItemString(module_dict, pre_handler);
    PyObject *arglist = Py_BuildValue("(s#)", aString.Ptr(),aString.Length()) ;

    PyObject *result = PyEval_CallObject(expression, arglist);

    response = PyString_AsString( result ) ;

    r_len = strlen( response ) ;
    }

    // Make a Symbian descriptor pointer to the char * response
    TPtrC8 symResponse((TUint8*)response, r_len ) ;

    // Clean-up, and restore thread state

    PyEval_SaveThread();
    CleanupStack::PopAndDestroy(it); 
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}