【发布时间】:2011-10-10 15:23:42
【问题描述】:
我目前正在将我的所有 C++ 引擎类绑定到 python 以用于游戏脚本。 最新的挑战是,当你在脚本中创建一个字符串时,例如
string = 'hello world'
这变成了一个 PyUnicodeObject。接下来,我们要在脚本中从绑定的 C 端函数调用此对象的函数。 PrintToLog(string),例如,可以说这个 c-function 就是这样
void PrintToLog( const char * thisString )
{
//file IO stuff as expected
myLog << thisString;
//more stuff involving fileIO
}
所以我的绑定需要从 PyUnicodeObject 中提取一个 char * ,它首先由 python 传递给我的通用函数处理程序,然后它将提取 pyobjects 并将其转换为正确的 c 端类型并将其传递给我的功能。
我能找到的唯一函数提取 wchar_t*... 无论如何都可以获得 ascii 表示,因为我们只会使用 ascii 字符集。
编辑:我正在使用 Python 3.2,其中所有字符串都是 unicode
【问题讨论】:
标签: python string unicode binding ascii