update file.write_bytes to support bytearray + bit_converter bytearray support
This commit is contained in:
parent
6bf23e5cac
commit
bfdd92ca51
@ -68,19 +68,19 @@ local function floatOrDoubleToBytes(val, opt)
|
|||||||
if opt == 'd' then
|
if opt == 'd' then
|
||||||
val = mantissa
|
val = mantissa
|
||||||
for i = 1, 6 do
|
for i = 1, 6 do
|
||||||
table.insert(bytes, math.floor(val) % (2 ^ 8))
|
bytes[#bytes + 1] = math.floor(val) % (2 ^ 8)
|
||||||
val = math.floor(val / (2 ^ 8))
|
val = math.floor(val / (2 ^ 8))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
table.insert(bytes, math.floor(mantissa) % (2 ^ 8))
|
bytes[#bytes + 1] = math.floor(mantissa) % (2 ^ 8)
|
||||||
val = math.floor(mantissa / (2 ^ 8))
|
val = math.floor(mantissa / (2 ^ 8))
|
||||||
table.insert(bytes, math.floor(val) % (2 ^ 8))
|
bytes[#bytes + 1] = math.floor(val) % (2 ^ 8)
|
||||||
val = math.floor(val / (2 ^ 8))
|
val = math.floor(val / (2 ^ 8))
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(bytes, math.floor(exponent * ((opt == 'd') and 16 or 128) + val) % (2 ^ 8))
|
bytes[#bytes + 1] = math.floor(exponent * ((opt == 'd') and 16 or 128) + val) % (2 ^ 8)
|
||||||
val = math.floor((exponent * ((opt == 'd') and 16 or 128) + val) / (2 ^ 8))
|
val = math.floor((exponent * ((opt == 'd') and 16 or 128) + val) / (2 ^ 8))
|
||||||
table.insert(bytes, math.floor(sign * 128 + val) % (2 ^ 8))
|
bytes[#bytes + 1] = math.floor(sign * 128 + val) % (2 ^ 8)
|
||||||
val = math.floor((sign * 128 + val) / (2 ^ 8))
|
val = math.floor((sign * 128 + val) / (2 ^ 8))
|
||||||
|
|
||||||
if not endianness then
|
if not endianness then
|
||||||
|
|||||||
@ -141,10 +141,13 @@ static int l_file_write_bytes(lua::State* L) {
|
|||||||
|
|
||||||
fs::path path = resolve_path(lua::require_string(L, pathIndex));
|
fs::path path = resolve_path(lua::require_string(L, pathIndex));
|
||||||
|
|
||||||
|
if (auto bytearray = lua::touserdata<lua::Bytearray>(L, -1)) {
|
||||||
|
auto& bytes = bytearray->data();
|
||||||
|
return lua::pushboolean(L, files::write_bytes(path, bytes.data(), bytes.size()));
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<ubyte> bytes;
|
std::vector<ubyte> bytes;
|
||||||
|
|
||||||
int result = read_bytes_from_table(L, -1, bytes);
|
int result = read_bytes_from_table(L, -1, bytes);
|
||||||
|
|
||||||
if(result != 1) {
|
if(result != 1) {
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user