View Single Post
Old 11-06-2007, 14:37   #5
marco.r
Senior Member
 
Iscritto dal: Dec 2005
Città: Istanbul
Messaggi: 1817
Innanzi tutto rispondo alla mia domanda.
A quanto pare non funziona mettendo tutto vuoto, bisogna importare il modulo principale, e operare da li'.

Codice:
    Py_Initialize();
    pythonModule = object(handle<>(borrowed(PyImport_AddModule("__main__"))));
    global = pythonModule.attr("__dict__");
    object result = exec_file("test.py", global, global);
    object test = global['x'];
    cout << (extract< int >(test)) << endl;
    object test2 = global["Klass"];
    object instance = test2();
    cout << (extract< int >(instance.attr("go")())) << endl;
In questo modo sembra andare, anche se non capisco perche' debba usare PyImport invece che boost:ython::import... mah.
__________________
One of the conclusions that we reached was that the "object" need not be a primitive notion in a programming language; one can build objects and their behaviour from little more than assignable value cells and good old lambda expressions. —Guy Steele
marco.r è offline   Rispondi citando il messaggio o parte di esso