mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
removed require to define available, tell, seek in ioLib
This commit is contained in:
parent
21019e6737
commit
82da7e907d
5 changed files with 20 additions and 45 deletions
|
|
@ -98,10 +98,6 @@ function lib.tell(descriptor)
|
|||
return positions[descriptor]
|
||||
end
|
||||
|
||||
function lib.flush(descriptor)
|
||||
requireDescriptor(descriptor)
|
||||
end
|
||||
|
||||
function lib.available(descriptor)
|
||||
requireDescriptor(descriptor)
|
||||
|
||||
|
|
|
|||
|
|
@ -60,18 +60,6 @@ function lib.write(fd, bytearray)
|
|||
end
|
||||
end
|
||||
|
||||
function lib.seek(fd, mode, offset)
|
||||
error("cannot seek the named pipe")
|
||||
end
|
||||
|
||||
function lib.tell(fd)
|
||||
error("cannot tell the named pipe")
|
||||
end
|
||||
|
||||
function lib.flush(fd)
|
||||
-- no flush on unix
|
||||
end
|
||||
|
||||
function lib.available(fd)
|
||||
if fd == nil or fd < 0 then return 0 end
|
||||
|
||||
|
|
|
|||
|
|
@ -97,14 +97,6 @@ function lib.write(handle, bytearray)
|
|||
end
|
||||
end
|
||||
|
||||
function lib.seek(handle, mode, offset)
|
||||
error("cannot seek the named pipe")
|
||||
end
|
||||
|
||||
function lib.tell(handle)
|
||||
error("cannot tell the named pipe")
|
||||
end
|
||||
|
||||
function lib.flush(handle)
|
||||
C.FlushFileBuffers(handle)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -32,18 +32,6 @@ function lib.write(descriptor, data)
|
|||
sockets[descriptor]:send(data)
|
||||
end
|
||||
|
||||
function lib.seek(descriptor, mode, offset)
|
||||
error("cannot seek socket")
|
||||
end
|
||||
|
||||
function lib.tell(descriptor)
|
||||
error("cannot tell socket")
|
||||
end
|
||||
|
||||
function lib.flush(descriptor)
|
||||
requireDescriptor(descriptor)
|
||||
end
|
||||
|
||||
function lib.available(descriptor)
|
||||
requireDescriptor(descriptor)
|
||||
|
||||
|
|
|
|||
|
|
@ -47,15 +47,14 @@ binaryMode - if enabled, most methods will expect bytes instead of strings
|
|||
ioLib - I/O library. Should include the following functions:
|
||||
read(descriptor: int, length: int) -> Bytearray
|
||||
May return bytearray with a smaller size if bytes have not arrived yet or have run out
|
||||
May throw error if descriptor isn't readable
|
||||
write(descriptor: int, data: Bytearray)
|
||||
seek(descriptor: int, mode: string, offset: int)
|
||||
May throw error if descriptor isn't writeable
|
||||
[optional] seek(descriptor: int, mode: string, offset: int)
|
||||
Mode may be 'b' (relative begin), 'c' (relative current), 'e' (relative end + 1)
|
||||
May throw error if environment is not support seek
|
||||
tell(descriptor: int) -> int
|
||||
May throw error if environment is not support tell
|
||||
flush(descriptor: int)
|
||||
available(descriptor: int) -> int
|
||||
May return 0 if environment is not support available method
|
||||
[optional] tell(descriptor: int) -> int
|
||||
[optional] flush(descriptor: int)
|
||||
[optional] available(descriptor: int) -> int
|
||||
is_alive(descriptor: int) -> bool
|
||||
close(descriptor: int)
|
||||
--]]
|
||||
|
|
@ -135,7 +134,7 @@ function io_stream:available(length)
|
|||
|
||||
available = #self.readBuffer
|
||||
else
|
||||
available = self.ioLib.available(self.descriptor)
|
||||
available = self.ioLib.available and self.ioLib.available(self.descriptor) or 0
|
||||
end
|
||||
|
||||
if not length then
|
||||
|
|
@ -388,10 +387,18 @@ function io_stream:write(arg, ...)
|
|||
end
|
||||
|
||||
function io_stream:seek(mode, offset)
|
||||
if not self.ioLib.seek then
|
||||
error("cannot seek this stream")
|
||||
end
|
||||
|
||||
self.ioLib.seek(self.descriptor, mode, offset)
|
||||
end
|
||||
|
||||
function io_stream:tell()
|
||||
if not self.ioLib.tell then
|
||||
error("cannot tell this stream")
|
||||
end
|
||||
|
||||
return self.ioLib.tell(self.descriptor)
|
||||
end
|
||||
|
||||
|
|
@ -418,7 +425,11 @@ function io_stream:flush()
|
|||
self.writeBuffer:clear()
|
||||
end
|
||||
|
||||
if self.flushMode ~= FLUSH_MODE_ONLY_BUFFER then self.ioLib.flush(self.descriptor) end
|
||||
if self.flushMode ~= FLUSH_MODE_ONLY_BUFFER then
|
||||
if self.ioLib.flush then
|
||||
self.ioLib.flush(self.descriptor)
|
||||
elseif self:is_closed() then error("stream is closed") end
|
||||
end
|
||||
end
|
||||
|
||||
return io_stream
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue