-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex20.5.lua
More file actions
37 lines (35 loc) · 758 Bytes
/
ex20.5.lua
File metadata and controls
37 lines (35 loc) · 758 Bytes
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
local function FileAsArray(FileName)
local File = assert(io.open(FileName, "r+b"))
local proxy = {}
local mt = {
__index = function (_, i)
File:seek("set", i)
return File:read(1)
end,
__newindex = function (_, i, b)
File:seek("set", i)
File:write(b)
end,
__pairs = function ()
return function (_, i)
i = i or 0
File:seek("set", i)
local v = File:read(1)
i = i + 1
return i, v
end
end,
__len = function ()
return File:seek("end")
end
}
setmetatable(proxy, mt)
return proxy
end
local p = FileAsArray("ex20.5.lua")
print(#p)
-- print(p[0])
-- p[0] = "T"
for _, b in pairs(p) do
io.write(b)
end