To best explain my problem, here is some code:

struct A
{
        A()
        {
                mTest = 1;

                std::cout << "Test: " << mTest;

                Py_Initialize();
                object main_module = import("__main__");
                object main_namespace = main_module.attr("__dict__");

                main_namespace["A_Instance"] = this;

                object result = exec_file(str("test.py"), main_namespace, 
main_namespace);

                std::cout << "Test: " << mTest;
        }

        int mTest;
}

in main.cpp or similar:

BOOST_PYTHON_MODULE(MyModule)
{
    class_<A>("A", init<>())
        .def_readwrite("Test", &A::mTest)
    ;
}

test.py:

from MyModule import *

A_Instance.Test = 5


Essentially I want to be able to access and modify the properties of an 
instance of a C++ class
at runtime.

When I try code similar to above, python excepts, as I believe it attempts to 
copy-construct
the A class instead of just pass the reference (this) so that i can modify it.

Is what I want possible? If not what would be a better way to do it?

-- 
file offset <[EMAIL PROTECTED]>

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to