Closed abesto closed 2 years ago
After taking a look at https://github.com/Panakotta00/FicsIt-Networks/blob/361f9effbc12a8e67f9887adaf3146c8f52fba0c/Source/FicsItNetworks/FicsItKernel/Processor/Lua/LuaFileSystemAPI.cpp#L371-L383 it seems like this read
implementation takes the number of bytes to read? (Didn't verify, I'm out of time for playing with this for today unfortunately). If that's correct, then this is the problem, as this is not how :read()
works in Lua (as documented at the page the FicsIt-Networks docs point to: https://www.lua.org/pil/21.1.html)
Thats right, At some point in development I choose to ditch buffered streams, previously we had them implemented and there they were implemented behind my VFS abstraction (little pana not knowing yet how it should actually happen)... I havent added a buffered reader in the end to before the abstraction, because now it seems actually more "realistic" and it is more similar to the API of open computers :3 The buffer and API similar to Lua can be implemented in Lua directly. Its just, I'm very Lazy in regards of documentation and havent updated it yet.
Understood :) Yeah given this, I could now easily implement my own read_all
function. Worth calling out in docs whenever you get to it: math.huge
(i.e. inf
) does not play nice with file:read
, an actual integer is required.
Current way of read all:
words = ""
while true do
local r = file:read(256)
if not r then break end
words = words .. r
end
Thats the old method but it does the job... there is a faster method in regards of Lua speed... dont know it out of my head right now tho
Maybe I'm doing something completely wrong, but: in all ways I've tried, reading from disks doesn't seem to work. Note that
filesystem.doFile
does work; here's a minimal script to reproduce:And the full output:
This behavior seems consistent across both
tmpfs
and drive holder / disk backed mounts (also no content is read with justfr:read()
, without the"*all"
;fr:read()
then returnsnil
instead of an empty string)