-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibcompat.lua
More file actions
56 lines (47 loc) · 1.09 KB
/
libcompat.lua
File metadata and controls
56 lines (47 loc) · 1.09 KB
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
local std = {}
local function fake_loadapi(_)
error("os.loadAPI and os.unloadAPI were specifically omitted from libcompat due to various issues. Please use require() instead.")
end
local function fake_fs_combine(...)
local pl = require("pl") -- Penlight: https://stevedonovan.github.io/Penlight/api/libraries/pl.path.html#join
return pl.join(...)
end
local function is_recrafted()
if pcall(require, "rc") then
return true
else
return false
end
end
local function is_phoenix()
if pcall(require, "craftos") then
return true
else
return false
end
end
local function is_other()
if not _G.fs and not _G.http then
return true
else
return false
end
end
if is_phoenix() then
std = require("craftos")
elseif is_recrafted() then
std = _G
for name, func in pairs(require("rc")) do
std.os[name] = func
end
elseif is_other() then
error("Unsupported system detected.")
else
std = _G -- Assume this is stock CraftOS
end
std.os.loadAPI = fake_loadapi
std.os.unloadAPI = fake_loadapi
if not std.fs.combine then
fs.combine = fake_fs_combine
end
return std