-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequire.lua
More file actions
49 lines (38 loc) · 1.2 KB
/
Copy pathrequire.lua
File metadata and controls
49 lines (38 loc) · 1.2 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
local function valid_library(library)
return type(library) == "table"
and type(library.RegisterInput) == "function"
and type(library.EnsureInput) == "function"
and type(library.AttachHostInputs) == "function"
end
if valid_library(_G.InlineInput) then
return _G.InlineInput
end
local function script_dir()
local source = debug and debug.getinfo and debug.getinfo(1, "S").source or nil
if type(source) ~= "string" then
return nil
end
if string.sub(source, 1, 1) == "@" then
source = string.sub(source, 2)
end
return string.match(source, "^(.*[/\\])[^/\\]+$")
end
local function add_candidate(candidates, path)
if type(path) == "string" and path ~= "" then
table.insert(candidates, path)
end
end
local candidates = {}
local base_path = script_dir()
add_candidate(candidates, base_path and base_path .. "inlineinput.lua")
add_candidate(candidates, ModPath and ModPath .. "inlineinput.lua")
add_candidate(candidates, "InlineInput/inlineinput.lua")
add_candidate(candidates, "mods/InlineInput/inlineinput.lua")
for _, path in ipairs(candidates) do
local ok, loaded = pcall(dofile, path)
local library = ok and loaded or _G.InlineInput
if valid_library(library) then
return library
end
end
return nil