mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-18 11:48:02 -04:00
Add decimals to file:read("*n")
This commit is contained in:
parent
ff2d0342e1
commit
d6d8d0b08a
@ -114,15 +114,15 @@ function buffer:read(...)
|
|||||||
end
|
end
|
||||||
local buffer = ""
|
local buffer = ""
|
||||||
local first = true
|
local first = true
|
||||||
|
local decimal = false
|
||||||
local last = false
|
local last = false
|
||||||
local hex = false
|
local hex = false
|
||||||
local pat = "^[0-9]+"
|
local pat = "^[0-9]+"
|
||||||
local minbuf = 3 -- "+0x" (sign + hexadecimal tag)
|
local minbuf = 3 -- "+0x" (sign + hexadecimal tag)
|
||||||
-- this function is used to read trailing numbers (1e2, 0x1p2, etc)
|
-- this function is used to read trailing numbers (1e2, 0x1p2, etc)
|
||||||
local function readnum()
|
local function readnum(checksign)
|
||||||
local _buffer = ""
|
local _buffer = ""
|
||||||
local sign = ""
|
local sign = ""
|
||||||
local checksign = true
|
|
||||||
while true do
|
while true do
|
||||||
if len(self.bufferRead) == 0 then
|
if len(self.bufferRead) == 0 then
|
||||||
local result, reason = readChunk()
|
local result, reason = readChunk()
|
||||||
@ -183,19 +183,33 @@ function buffer:read(...)
|
|||||||
end
|
end
|
||||||
minbuf = 0
|
minbuf = 0
|
||||||
first = false
|
first = false
|
||||||
|
elseif decimal then
|
||||||
|
local sep = sub(self.bufferRead, 1, 1)
|
||||||
|
if sep == "." then
|
||||||
|
buffer = buffer .. sep
|
||||||
|
self.bufferRead = sub(self.bufferRead, 2)
|
||||||
|
local temp = readnum(false) -- no sign
|
||||||
|
if temp then
|
||||||
|
buffer = buffer .. temp
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not tonumber(buffer) then break end
|
||||||
|
decimal = false
|
||||||
|
last = true
|
||||||
|
minbuf = 1
|
||||||
elseif last then
|
elseif last then
|
||||||
local tag = sub(self.bufferRead, 1, 1)
|
local tag = sub(self.bufferRead, 1, 1)
|
||||||
if hex and (tag == "p" or tag == "P") then
|
if hex and (tag == "p" or tag == "P") then
|
||||||
local temp = sub(self.bufferRead, 1, 1)
|
local temp = sub(self.bufferRead, 1, 1)
|
||||||
self.bufferRead = sub(self.bufferRead, 2)
|
self.bufferRead = sub(self.bufferRead, 2)
|
||||||
local temp2 = readnum() -- this eats the next sign if any
|
local temp2 = readnum(true) -- this eats the next sign if any
|
||||||
if temp2 then
|
if temp2 then
|
||||||
buffer = buffer .. temp .. temp2
|
buffer = buffer .. temp .. temp2
|
||||||
end
|
end
|
||||||
elseif tag == "e" or tag == "E" then
|
elseif tag == "e" or tag == "E" then
|
||||||
local temp = sub(self.bufferRead, 1, 1)
|
local temp = sub(self.bufferRead, 1, 1)
|
||||||
self.bufferRead = sub(self.bufferRead, 2)
|
self.bufferRead = sub(self.bufferRead, 2)
|
||||||
local temp2 = readnum() -- this eats the next sign if any
|
local temp2 = readnum(true) -- this eats the next sign if any
|
||||||
if temp2 then
|
if temp2 then
|
||||||
buffer = buffer .. temp .. temp2
|
buffer = buffer .. temp .. temp2
|
||||||
end
|
end
|
||||||
@ -204,9 +218,8 @@ function buffer:read(...)
|
|||||||
else
|
else
|
||||||
local x,y = string.find(self.bufferRead, pat)
|
local x,y = string.find(self.bufferRead, pat)
|
||||||
if not x then
|
if not x then
|
||||||
if not tonumber(buffer) then break end
|
minbuf = 1
|
||||||
minbuf = 3
|
decimal = true
|
||||||
last = true
|
|
||||||
else
|
else
|
||||||
buffer = buffer .. sub(self.bufferRead, 1, y)
|
buffer = buffer .. sub(self.bufferRead, 1, y)
|
||||||
self.bufferRead = sub(self.bufferRead, y + 1)
|
self.bufferRead = sub(self.bufferRead, y + 1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user