publishing an already instantiated class

J

J

Hi everyone,

Thanks for your awsome replies. I started replacing Javascript
with python 2 days ago and I already have my first scripts running.
Mainly due to the wealth of information in this blog.

I have a C++ object that is already instantiated and now
I want to give python a reference to it... Basically I have

class X
{
typedef struct
{
PyObject_HEAD
ScnNode* mObject;
} PyStruct;

static PyTypeObject PyType;

static init()
{
PyType_Ready(&PyType) < 0)
Py_INCREF(&PyType);
PyModule_AddObject(sModule, "Node", (PyObject*) &PyType);
}
};

I think that in the constructor of X I now have to make some calls in
order to provide access to this instance from a python script.... I
also think that I only want to get PyObject_New to be called, but not
PyObject_Init, because there I create a new instance of X when it is
instantiated through a script.... Am I on the right track here ?

Cheers
Jochen
 
J

J

I think I just found my own solution, so I will record it for future
references

I did this in my Constructor of X
{
PyStruct* lObject;
lObject = PyObject_New(PyStruct, &X::pyType);
lObject->mObject = this;
}

What does everyone think about this. I am posting a little bit out of
the hip here,
and should probably investigate my solution a little more.
Nevertheless, it is
a good way to record my experiences...

Cheers
Jochen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top