mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-09 04:51:49 +00:00
camelCase in some stream providers changed to snake_case
This commit is contained in:
parent
7d148ae2cf
commit
2bbcb77bcf
2 changed files with 50 additions and 50 deletions
|
|
@ -5,73 +5,73 @@ local lib = { }
|
||||||
local buffers = { }
|
local buffers = { }
|
||||||
local positions = { }
|
local positions = { }
|
||||||
|
|
||||||
local nextDescriptor = 0
|
local next_descriptor = 0
|
||||||
|
|
||||||
local function openDescriptor(buffer)
|
local function open_descriptor(buffer)
|
||||||
nextDescriptor = nextDescriptor + 1
|
next_descriptor = next_descriptor + 1
|
||||||
|
|
||||||
buffers[nextDescriptor] = buffer
|
buffers[next_descriptor] = buffer
|
||||||
positions[nextDescriptor] = 1
|
positions[next_descriptor] = 1
|
||||||
|
|
||||||
return nextDescriptor
|
return next_descriptor
|
||||||
end
|
end
|
||||||
|
|
||||||
local function requireDescriptor(descriptor)
|
local function require_descriptor(descriptor)
|
||||||
if not buffers[descriptor] then
|
if not buffers[descriptor] then
|
||||||
error("unknown descriptor")
|
error("unknown descriptor")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function lib.read(descriptor, length)
|
function lib.read(descriptor, length)
|
||||||
requireDescriptor(descriptor)
|
require_descriptor(descriptor)
|
||||||
|
|
||||||
local buf = buffers[descriptor]
|
local buf = buffers[descriptor]
|
||||||
local bufLength = #buf
|
local buf_length = #buf
|
||||||
local pos = positions[descriptor]
|
local pos = positions[descriptor]
|
||||||
|
|
||||||
local toRead = math.min(bufLength - pos + 1, length)
|
local to_read = math.min(buf_length - pos + 1, length)
|
||||||
|
|
||||||
if toRead <= 0 then
|
if to_read <= 0 then
|
||||||
return Bytearray()
|
return Bytearray()
|
||||||
end
|
end
|
||||||
|
|
||||||
local segment = buf:slice(pos, toRead)
|
local segment = buf:slice(pos, to_read)
|
||||||
|
|
||||||
positions[descriptor] = pos + toRead
|
positions[descriptor] = pos + to_read
|
||||||
|
|
||||||
return segment
|
return segment
|
||||||
end
|
end
|
||||||
|
|
||||||
function lib.write(descriptor, data)
|
function lib.write(descriptor, data)
|
||||||
requireDescriptor(descriptor)
|
require_descriptor(descriptor)
|
||||||
|
|
||||||
local buf = buffers[descriptor]
|
local buf = buffers[descriptor]
|
||||||
local pos = positions[descriptor]
|
local pos = positions[descriptor]
|
||||||
|
|
||||||
local bufLength = #buf
|
local buf_length = #buf
|
||||||
local dataLength = #data
|
local data_length = #data
|
||||||
|
|
||||||
local endPos = pos + dataLength - 1
|
local end_pos = pos + data_length - 1
|
||||||
|
|
||||||
-- size ensuring
|
-- size ensuring
|
||||||
if endPos > bufLength then
|
if endPos > buf_length then
|
||||||
for i = bufLength + 1, endPos do
|
for i = buf_length + 1, end_pos do
|
||||||
buf[i] = 0
|
buf[i] = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for i = 1, dataLength do
|
for i = 1, data_length do
|
||||||
buf[i + pos - 1] = data[i]
|
buf[i + pos - 1] = data[i]
|
||||||
end
|
end
|
||||||
|
|
||||||
positions[descriptor] = pos + dataLength
|
positions[descriptor] = pos + data_length
|
||||||
end
|
end
|
||||||
|
|
||||||
function lib.seek(descriptor, mode, offset)
|
function lib.seek(descriptor, mode, offset)
|
||||||
requireDescriptor(descriptor)
|
require_descriptor(descriptor)
|
||||||
|
|
||||||
local buf = buffers[descriptor]
|
local buf = buffers[descriptor]
|
||||||
local bufLength = #buf
|
local buf_length = #buf
|
||||||
|
|
||||||
local base
|
local base
|
||||||
|
|
||||||
|
|
@ -80,26 +80,26 @@ function lib.seek(descriptor, mode, offset)
|
||||||
elseif mode == 'c' then
|
elseif mode == 'c' then
|
||||||
base = positions[descriptor]
|
base = positions[descriptor]
|
||||||
elseif mode == 'e' then
|
elseif mode == 'e' then
|
||||||
base = bufLength + 1
|
base = buf_length + 1
|
||||||
else error('invalid seek mode') end
|
else error('invalid seek mode') end
|
||||||
|
|
||||||
local newPos = base + offset
|
local new_pos = base + offset
|
||||||
|
|
||||||
if newPos < 1 then
|
if new_pos < 1 then
|
||||||
error('failed to seek stream')
|
error('failed to seek stream')
|
||||||
end
|
end
|
||||||
|
|
||||||
positions[descriptor] = newPos
|
positions[descriptor] = new_pos
|
||||||
end
|
end
|
||||||
|
|
||||||
function lib.tell(descriptor)
|
function lib.tell(descriptor)
|
||||||
requireDescriptor(descriptor)
|
require_descriptor(descriptor)
|
||||||
|
|
||||||
return positions[descriptor]
|
return positions[descriptor]
|
||||||
end
|
end
|
||||||
|
|
||||||
function lib.available(descriptor)
|
function lib.available(descriptor)
|
||||||
requireDescriptor(descriptor)
|
require_descriptor(descriptor)
|
||||||
|
|
||||||
local buf = buffers[descriptor]
|
local buf = buffers[descriptor]
|
||||||
local pos = positions[descriptor]
|
local pos = positions[descriptor]
|
||||||
|
|
@ -112,20 +112,20 @@ function lib.is_alive(descriptor)
|
||||||
end
|
end
|
||||||
|
|
||||||
function lib.close(descriptor)
|
function lib.close(descriptor)
|
||||||
requireDescriptor(descriptor)
|
require_descriptor(descriptor)
|
||||||
|
|
||||||
buffers[descriptor] = nil
|
buffers[descriptor] = nil
|
||||||
positions[descriptor] = nil
|
positions[descriptor] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
return function(buffer, binaryMode)
|
return function(buffer, binary_mode)
|
||||||
if binaryMode == nil then
|
if binary_mode == nil then
|
||||||
binaryMode = true
|
binary_mode = true
|
||||||
end
|
end
|
||||||
|
|
||||||
return io_stream.new(
|
return io_stream.new(
|
||||||
openDescriptor(buffer),
|
open_descriptor(buffer),
|
||||||
binaryMode,
|
binary_mode,
|
||||||
lib
|
lib
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
@ -4,36 +4,36 @@ local lib = { }
|
||||||
|
|
||||||
local sockets = { }
|
local sockets = { }
|
||||||
|
|
||||||
local nextDescriptor = 0
|
local next_descriptor = 0
|
||||||
|
|
||||||
local function openDescriptor(socket)
|
local function open_descriptor(socket)
|
||||||
nextDescriptor = nextDescriptor + 1
|
next_descriptor = next_descriptor + 1
|
||||||
|
|
||||||
sockets[nextDescriptor] = socket
|
sockets[next_descriptor] = socket
|
||||||
|
|
||||||
return nextDescriptor
|
return next_descriptor
|
||||||
end
|
end
|
||||||
|
|
||||||
local function requireDescriptor(descriptor)
|
local function require_descriptor(descriptor)
|
||||||
if not sockets[descriptor] then
|
if not sockets[descriptor] then
|
||||||
error("unknown descriptor")
|
error("unknown descriptor")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function lib.read(descriptor, length)
|
function lib.read(descriptor, length)
|
||||||
requireDescriptor(descriptor)
|
require_descriptor(descriptor)
|
||||||
|
|
||||||
return sockets[descriptor]:recv(length)
|
return sockets[descriptor]:recv(length)
|
||||||
end
|
end
|
||||||
|
|
||||||
function lib.write(descriptor, data)
|
function lib.write(descriptor, data)
|
||||||
requireDescriptor(descriptor)
|
require_descriptor(descriptor)
|
||||||
|
|
||||||
sockets[descriptor]:send(data)
|
sockets[descriptor]:send(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
function lib.available(descriptor)
|
function lib.available(descriptor)
|
||||||
requireDescriptor(descriptor)
|
require_descriptor(descriptor)
|
||||||
|
|
||||||
return sockets[descriptor]:available()
|
return sockets[descriptor]:available()
|
||||||
end
|
end
|
||||||
|
|
@ -45,20 +45,20 @@ function lib.is_alive(descriptor)
|
||||||
end
|
end
|
||||||
|
|
||||||
function lib.close(descriptor)
|
function lib.close(descriptor)
|
||||||
requireDescriptor(descriptor)
|
require_descriptor(descriptor)
|
||||||
|
|
||||||
sockets[descriptor]:close()
|
sockets[descriptor]:close()
|
||||||
sockets[descriptor] = nil
|
sockets[descriptor] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
return function(socket, binaryMode)
|
return function(socket, binary_mode)
|
||||||
if binaryMode == nil then
|
if binary_mode == nil then
|
||||||
binaryMode = true
|
binary_mode = true
|
||||||
end
|
end
|
||||||
|
|
||||||
return io_stream.new(
|
return io_stream.new(
|
||||||
openDescriptor(socket),
|
open_descriptor(socket),
|
||||||
binaryMode,
|
binary_mode,
|
||||||
lib
|
lib
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
Loading…
Add table
Add a link
Reference in a new issue