I am currently binding all of my C++ engine classes to python for game play scripting purposes. The latest challenge is that when say you make a variable in the script a string such as
string = 'hello world'
this becomes a PyUnicodeObject. Next we want to call a function on this object in the script from a bound C side function. PrintToLog( string ), as an example lets say this c-function is as such
void PrintToLog( const char * thisString )
{
//file IO stuff as expected
myLog << thisString;
//more stuff involving fileIO
}
So my binding needs to extract a char * from the PyUnicodeObject which will be passed at first by the python to my generic function handler, which in turn will extract and covert the pyobjects to the proper c-side type and pass it to my function.
The only function I can find extracts a wchar_t*... Is there anyway to get the ascii representation since we will only be using the ascii character set.
EDIT: I am using Python 3.2 where all strings are unicode
I believe the function you're looking for is PyUnicode_AsASCIIString. This will give you a non-unicode (ASCII) python string. And then you can take the normal approach for extracting a char*
from that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With