我正在使用 Boost.Python 来公开 JRA 的BWRepLib所以我可以尝试在 python 中对 sc:bw 重播进行一些数据挖掘,但我遇到了一个从 C++ 方法返回的值的小问题。当运行任何旧的简单程序(例如教程)时,我会得到返回给 python 的预期值(一个“hello,world”字符串,打印得很好)。但是,当我运行 bwreplib 程序时,我遇到了所有字符串都被截断并且某些整数返回方法返回意外值的问题。例如,在一次回放中,C++ 中的玩家名称正确返回,因为玩家 1 是 SlayerS_'BoxeR',玩家 2 是 iloveoov。然而,在 python 中打印出来的值是 erS_'Boxer' 和 eoov,缺少最初的 4 个字节/字符。另一个例子是玩家种族,它应该是整数值 1、2、3 或 6,但是我得到更大的不相关值,例如 97,120、111 和 78 但是某些值(例如 120 和 97)应该是同一个种族,并且在纯 C++ 程序中返回相同的值。正如我看到的数字之间没有二进制相关性,我怀疑这可能也被 python 中的一个单词所抵消,并从不同的位置返回一个值?有没有人遇到过类似的问题?
我对使用 Boost.Python 很陌生,而不是 C++ 专家。我可以发布包装器,但是除了公开诸如
class_<BWrepPlayer>("BWrepPlayer")
.def("getName", &BWrepPlayer::getName)
.def("getNumber", &BWrepPlayer::getNumber)
我怀疑我应该做一些特别的事情来包装我没有做的功能。但是在线搜索并阅读文档我找不到那会是什么,但是我相信一旦我发现它就会非常明显。
编辑:日志输出
...patience...
...patience...
...found 1547 targets...
...updating 4 targets...
compile-c-c++ bin\msvc-9.0\debug\threading-multi\BWrepAPI.obj
BWrepAPI.cpp
BWrepAPI.cpp(19) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\string.h(74) : see declaration of 'strcpy'
BWrepAPI.cpp(88) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\string.h(74) : see declaration of 'strcpy'
BWrepAPI.cpp(245) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\string.h(74) : see declaration of 'strcpy'
BWrepAPI.cpp(246) : warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\string.h(79) : see declaration of 'strcat'
BWrepAPI.cpp(259) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\string.h(74) : see declaration of 'strcpy'
BWrepAPI.cpp(265) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\string.h(74) : see declaration of 'strcpy'
BWrepAPI.cpp(277) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\string.h(74) : see declaration of 'strcpy'
BWrepAPI.cpp(323) : warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\stdio.h(237) : see declaration of 'fopen'
msvc.link.dll bin\msvc-9.0\debug\threading-multi\pybwrep.pyd
Creating library bin\msvc-9.0\debug\threading-multi\pybwrep.lib and object bin\msvc-9.0\debug\threading-multi\pybwrep.exp
msvc.manifest.dll bin\msvc-9.0\debug\threading-multi\pybwrep.pyd
...updated 4 targets...