我哈瓦一类,如:如何通过LUA字符串(二进制)到C++使用tolua ++
class SomeClass
{
void initFromBuffer(void* buffer,int length);
void initFromString(const std::string& str);
}
使用tolua ++,有像绑定:
static int SomeClass_initFromBuffer00(lua_State* tolua_S)
{
SomeClass* self = (SomeClass*) tolua_tousertype(tolua_S,1,0);
void* buffer = ((void*) tolua_touserdata(tolua_S,2,0));
int length = ((int) tolua_tonumber(tolua_S,3,0));
self->initFromBuffer(buffer,length);
}
和:
static int SomeClass_initFromString00(lua_State* tolua_S)
{
SomeClass* self = (SomeClass*) tolua_tousertype(tolua_S,1,0);
const std::string str = ((const std::string) tolua_tocppstring(tolua_S,2,0));
self->initFromString(str);
tolua_pushcppstring(tolua_S,(const char*)str);
}
现在,我想要从lua传递二进制数据到C++,二进制文件中有'\ 0',所以如果我使用initFromString来传递它,二进制数据将被修剪。但是,如果我使用initFromBuffer来传递它,我得到坏void ptr'void * buffer =((void *)tolua_touserdata(tolua_S,2,0));指针为空。
那么,我怎么能将二进制字符串从lua传递到C++?