replace Bytearray with FFI implementation
This commit is contained in:
@@ -109,13 +109,13 @@ static int l_send(lua::State* L, network::Network& network) {
|
||||
}
|
||||
lua::pop(L);
|
||||
connection->send(buffer.data(), size);
|
||||
} else if (auto bytes = lua::touserdata<lua::LuaBytearray>(L, 2)) {
|
||||
connection->send(
|
||||
reinterpret_cast<char*>(bytes->data().data()), bytes->data().size()
|
||||
);
|
||||
} else if (lua::isstring(L, 2)) {
|
||||
auto string = lua::tolstring(L, 2);
|
||||
connection->send(string.data(), string.length());
|
||||
} else {
|
||||
auto string = lua::bytearray_as_string(L, 2);
|
||||
connection->send(string.data(), string.length());
|
||||
lua::pop(L);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -140,13 +140,10 @@ static int l_recv(lua::State* L, network::Network& network) {
|
||||
lua::pushinteger(L, buffer[i] & 0xFF);
|
||||
lua::rawseti(L, i+1);
|
||||
}
|
||||
return 1;
|
||||
} else {
|
||||
lua::newuserdata<lua::LuaBytearray>(L, size);
|
||||
auto bytearray = lua::touserdata<lua::LuaBytearray>(L, -1);
|
||||
bytearray->data().reserve(size);
|
||||
std::memcpy(bytearray->data().data(), buffer.data(), size);
|
||||
return lua::create_bytearray(L, buffer.data(), size);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_available(lua::State* L, network::Network& network) {
|
||||
|
||||
Reference in New Issue
Block a user