加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

使用UCS-4对Python进行Swig绑定

发布时间:2020-12-20 13:24:23 所属栏目:Python 来源:网络整理
导读:有谁知道是否有办法使SWIG编码字符串为UCS-4 for Python? SWIG文档声明可以使用类型映射,但不提供任何其他详细信息或示例. 对于上下文,我正在使用一组Python脚本扩展Blender 3D软件.我们需要将这些脚本与各种机器人软件连接起来,我们使用SWIG来编译Python库
有谁知道是否有办法使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 *,然后弄清楚如何在必要时手动转换它.听起来它开始时很麻烦.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读