void PythonWrapper::Expose_MainMenu(sMainMenu &menu)
{
try{
main_namespace["sMainMenu"] = boost::python::class_<sMainMenu>("sMainMenu")
.def("LoadImage",&sMainMenu::LoadImage)
.def("LoadSprite", &sMainMenu::LoadSprite)
.def("LoadButton",&sMainMenu::LoadButton);
main_namespace["menu"] = boost::python::ptr(&menu);
}
catch(boost::python::error_already_set const &){
std::string perror_str = parse_python_exception();
std::cout << "Error in Python: " << perror_str << std::endl;
}
}
Now in my python exposure of sMainMenu, I've only defined the functions I want python scripts to have access to... is this a mistake? Is this the reason my application either doesn't do anything or completely crashes? Do I need to define the class with every function and member of the class?
I know if I call the function twice, it'll crash from the double definition of sMainMenu (I'm going to pull it out into a module once it works.) The script is being "executed" by calling:
void PythonWrapper::Execute_Script()
{
try{
PyRun_String("import Main_Menu", Py_file_input, main_namespace.ptr(), main_namespace.ptr());
}
catch(boost::python::error_already_set const &){
std::string perror_str = parse_python_exception();
std::cout << "Error in Python: " << perror_str << std::endl;
}
}
I placed some prints through out the script but only the first one outputs to the command prompt. My script is:
print("Loaded the file...\n")
menu.LoadImage("resources/texture/background.png");
menu.LoadImage("resources/texture/biNewGame.png");
menu.LoadImage("resources/texture/baNewGame.png");
menu.LoadImage("resources/texture/biLoadGame.png");
menu.LoadImage("resources/texture/baLoadGame.png");
menu.LoadImage("resources/texture/biOptions.png");
menu.LoadImage("resources/texture/baOptions.png");
menu.LoadImage("resources/texture/biQuit.png");
menu.LoadImage("resources/texture/baQuit.png");
print("Loaded the images...\n")
menu.LoadSprite(0, 0, 0);
print("Loaded the background...\n")
menu.LoadButton(1, 2, 350, 174);
menu.LoadButton(3, 4, 333, 328);
menu.LoadButton(5, 6, 398, 483);
menu.LoadButton(7, 8, 455, 640);
print("Loaded the buttons...\n")
If I try to use boost::python::exec_file() the game crashes, hence the use instead of PyRun_String()