-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
41 lines (36 loc) · 1.12 KB
/
init.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
local M = {}
---@param source? string caller debug.getinfo(1).source
---@return string dir path to dir of calling script
---@nodiscard
local function get_script_dir(source)
source = source or debug.getinfo(1).source
local script = source:gsub("^@", ""):gsub("[\\/]", "/")
if script:match("^[a-zA-Z]:[\\/]") then
return "" .. script:gsub("[\\/]+[^\\/]*$", "")
end
local pwd_cmd = package.config:sub(1, 1) == "/" and "pwd" or "echo %cd%"
local pipe = io.popen(pwd_cmd)
local cwd = pipe and pipe:read("*l"):gsub("[\\/]+$", ""):gsub("[\\/]", "/")
if pipe then
pipe:close()
end
local dir = cwd or "."
if script:match("[\\/][^\\/]+$") then
dir = dir .. "/" .. script:gsub("[\\/]+[^\\/]*$", "")
end
return dir
end
local old_package_path = package.path
package.path = get_script_dir() .. "/?.lua"
M.arrays = require("arrays")
M.date = require("date")
M.files = require("files")
M.json = require("json")
M.paths = require("paths")
M.platform = require("platform")
M.sha2 = require("sha2")
M.strings = require("strings")
M.tables = require("tables")
M.yaml = require("yaml")
package.path = old_package_path
return M