[C++-sig] Global variables (standard C/C++ types)

pawell pablo_best at o2.pl
Wed Mar 12 01:14:37 CET 2008


I found (I think) some other solution. This code works as I expected:


int global_int = 666;
bool global_bool = 666;

struct PCFG {
};

PCFG tmp_pcfg;

BOOST_PYTHON_MODULE(my_app) {
    class_<PCFG>("PCFG")
        .def_readwrite("global_int",&global_int)
        .def_readwrite("global_bool",&global_bool)
    ;
    scope().attr("pcfg") = object(ptr(&tmp_pcfg));
}

int main(int argc, char** argv) {
    Py_Initialize();
    init__main__();
    initmy_app();
    Py_Main(argc,argv);
    Py_Finalize();
    std::cout << "global_int: " << global_int << std::endl;
    std::cout << "global_bool: " << global_bool << std::endl;
    return 0;
}


Now I can modify my_app.pcfg.global_bool or my_app.pcfg.global_int  and see
result in C++ :)
Is it ok to reference C++ global objects as Python class members?
-- 
View this message in context: http://www.nabble.com/Global-variables-%28standard-C-C%2B%2B-types%29-tp15968033p15995328.html
Sent from the Python - c++-sig mailing list archive at Nabble.com.




More information about the Cplusplus-sig mailing list