Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with embedded python
#1
I'm working on embedding python 3.6 into a C++ application.


To get the hang of how all this works I'm writing a function that simply posts a message to the debug log (as well as on screen). I've successfully exposed the function to python.

import test
test.debug("This is a debug Message")
The above will successfully call the function...however I can't seem to figure out how to get the argument back from python


My bindings look like this:

//Bindings to allow Python scripts to post Log infos
static PyObject* DebugInfo(PyObject *self, PyObject *args)
{
	std::string message = <MAGIC SHOULD HAPPEN HERE>;
	LOGINFO(message.c_str());
	return 0;
}
static PyMethodDef DebugInfo_Method[] =
{
	{ "Debug_Info", DebugInfo, METH_VARARGS,
          "Post message as Debug Info" },
{ NULL, NULL, 0, NULL }
};
//End of Log Infos Binding

//Define Python Modue and link to bindings
static PyModuleDef test =
{
	PyModuleDef_HEAD_INIT, "DebugInfo", NULL, -1, DebugInfo_Method,
	NULL, NULL, NULL, NULL
};

static PyObject* PyInit_test(void)
{
	return PyModule_Create(&test);
};
I may have done this completely wrong, I'm extremely new to working with python and c++.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to run detectron2, as python embedded code in C++, on GPU? hassaniqbal931 3 1,107 Nov-02-2023, 04:45 PM
Last Post: blabling2
  Adding libraries to embedded Python as a ZIP The_Oman 0 1,239 May-05-2023, 04:05 PM
Last Post: The_Oman
Bug Embedded Python Memory Leaks Alexei 1 1,033 Sep-16-2022, 01:15 PM
Last Post: Alexei
  Embedded Python in C++ Xeno 19 3,548 Aug-03-2022, 07:29 AM
Last Post: Gribouillis
  Embedded python fails to compile on Raspberry Pi tryfon 2 3,486 Dec-22-2020, 02:06 PM
Last Post: tryfon
  Can Embedded Python run any shared library on Android ? sprotz 0 2,329 Nov-08-2020, 12:21 PM
Last Post: sprotz
  memory leak on embedded python in c++ asdf3721 3 3,387 Jul-16-2020, 06:33 AM
Last Post: Gribouillis
  Embedded Python PyObject_CallObject function JRHeisey 1 2,391 Nov-27-2019, 01:50 AM
Last Post: casevh
  Trying to implement Python into embedded OS thesurya7 2 2,406 Apr-02-2019, 06:38 PM
Last Post: ebolisa
  Multiple calls to Python interpreter embedded in C++ application yield segmentation f mmoelle1 0 2,834 Mar-21-2019, 08:54 PM
Last Post: mmoelle1

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020