-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.lua
executable file
·46 lines (39 loc) · 1.08 KB
/
util.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
local util = {}
function util.read_file(file)
local rom = {}
if love then
if type(file) == "string" then
file = love.filesystem.newFile(file)
end
local ok, err = file:open("r")
if ok then
local address = 0
while (not file:isEOF()) do
local byte, len = file:read(1)
-- Dropped files don't seem to report EOF
if len ~= 1 or not string.byte(byte) then
break
end
rom[address] = string.byte(byte)
address = address + 1
end
file:close()
rom.size = address
return rom
else
print(err)
end
else
file = io.open(file, "r")
local address = 0
repeat
local b = file:read(1)
if b then rom[address] = b:byte() end
address = address + 1
until not b
rom.size = #rom
file:close()
end
return rom
end
return util