blob: 2a696533aacdd416514939cf540096773b9abf70 (
plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
-- bundler. public domain.
-- https://citrons.xyz/git/cc-bundler.git
local cc_host = {}
function cc_host.error(msg)
printError(msg)
end
function cc_host.list_dir(path)
local list = fs.list(shell.resolve(path))
local i = 0
return function()
i = i + 1
return list[i]
end
end
function cc_host.is_dir(path)
return fs.isDir(shell.resolve(path))
end
function cc_host.read(path)
local file = assert(fs.open(shell.resolve(path), "r"))
local data = assert(file.readAll())
file.close()
return data
end
function cc_host.write(path, content)
local file = assert(fs.open(shell.resolve(path), "w"))
file.write(content)
file.close()
end
local normal_host = {}
function normal_host.error(msg)
io.stderr:write(tostring(msg).."\n")
os.exit(-1)
end
function normal_host.list_dir(path)
return require "lfs".dir(path)
end
function normal_host.is_dir(path)
return require "lfs".attributes(path).mode == "directory"
end
function normal_host.read(path)
local file = assert(io.open(path, "r"))
local data = assert(file:read "a")
file:close()
return data
end
function normal_host.write(path, content)
local file = assert(io.open(path, "w"))
assert(file:write(content))
file:close()
end
if _HOST and _HOST:match "ComputerCraft" then
return cc_host
else
return normal_host
end
|