Reading Python script from file.
I had issues at first loading my scripts from files. I based my original implementation off of the embedding example on the python wiki. This worked perfectly however when I tried to switch the run function for one that would run from a file I got less than acceptable results. So what I ended up doing is reading the scripts into memory and then passing the string to that function. This has at least one pitfall and that is memory usage. On larger files you may run into memory usage issues but other than that it seems to work ok. Below is a stripped down version for anyone else trying to work around similar issues.
1: void RunScript(const char* filename)
3: FILE *file;
4: long fileSize=0;
5: char* buffer=NULL;
10: file = fopen(filename,"rb");
15: fileSize = ftell(file);
17: buffer = new char[fileSize];
21: handle<> ignored(( PyRun_String(buffer,
24: main_namespace.ptr() ) ));
25: delete buffer;
30: std::cout << "Script file could not be opened!" << std::endl;