我有一个testm函数,它返回一个std :: vector。
std::vector<unsigned char> readFromSlave(unsigned int _bits) {
std::vector<unsigned char> helpvector;
helpvector.push_back((unsigned char) 10);
helpvector.push_back((unsigned char) 20);
helpvector.push_back((unsigned char) 30);
helpvector.push_back((unsigned char) 40);
return helpvector;
}
并将其注册为lua(注册的重要部分):
x.def("readFromSlave", &readFromSlave, luabind::return_stl_iterator);
并在lua中调用该函数:
vector = readFromSlave(500);
for value in vector do
print(value)
end
它只能部分工作,它返回正确数量的元素,但值不正确。
示例输出为:
128
83
0
1
可能是什么问题?
(info)我已从示例中删除了类和名称空间以缩短它。