有谁知道是否有办法使SWIG编码字符串为UCS-4 for
Python?
SWIG文档声明可以使用类型映射,但不提供任何其他详细信息或示例.
对于上下文,我正在使用一组Python脚本扩展Blender 3D软件.我们需要将这些脚本与各种机器人软件连接起来,我们使用SWIG来编译Python库.
Blender使用自己的Python 3.2预编译了–with-wide-unicode选项,因此它使用UCS-4 unicode字符串.
然而,通过defatult SWIG将字符串编码为UCS-2,因此当与Blender接口时,我总是会遇到错误:“undefined symbol:PyUnicodeUCS2_ *”.
这是来自SWIG文档,也许你已经看到了这个:
At this time,SWIG provides limited support for Unicode and wide-character strings (the C wchar_t type). Some languages provide typemaps for wchar_t,but bear in mind these might not be portable across different operating systems. This is a delicate topic that is poorly understood by many programmers and not implemented in a consistent manner across languages. For those scripting languages that provide Unicode support,Unicode strings are often available in an 8-bit representation such as UTF-8 that can be mapped to the char * type (in which case the SWIG interface will probably work). If the program you are wrapping uses Unicode,there is no guarantee that Unicode characters in the target language will use the same internal representation (e.g.,UCS-2 vs. UCS-4). You may need to write some special conversion functions.
所以听起来你应该将它映射到char *,然后弄清楚如何在必要时手动转换它.听起来它开始时很麻烦.