[C++-sig] please help with simple program crashing
Drew Ferraro
gfilla at gmail.com
Thu Jul 1 07:52:03 CEST 2004
hi,
ive recently trying to add a scripting system to a game i am making..
anyway, ive started to learn python and am trying to figure out how to
embed it in my game. i have gotten a C++ function to work from inside
C++ but called from python via PyRun_SimpleString(),,, i can send
commands directly to the intepreter with that function, but im having
a problem
with PyRun_SimpleFile(). im trying to execute a python script with
this function, but its crashing when it gets to this line:
PyRun_SimpleFile(fp,"test.py");
i cant figure out what im doing wrong. here is the source. any help is
greatly appreciated!!
#include <boost/python.hpp>
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace boost::python;
#ifdef _WIN32
#pragma comment(lib,"boost_python.lib");
#endif
int main()
{
Py_Initialize();
FILE *fp = NULL;
fp = fopen("test.py", "r");
if(fp == NULL)
return 1;
PyRun_SimpleFile(fp,"test.py");
Py_Finalize();
system("PAUSE");
return 0;
}
thanks for any help! also, i tried not opening the file myself, and
just sending PR_SF() a NULL FILE*... it didnt crash! instead, in the
console it said there was a syntax error and printed out some garbage
characters... i dont think theres a syntax error, "text.py" entire
file just says print "hello world"
thanks again!
More information about the Cplusplus-sig
mailing list