diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-10-12 14:39:05 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-10-12 14:39:09 +0800 |
commit | 336eaae1db339f29b177aaa5fd05c46e4bde7368 (patch) | |
tree | 78c7906a756fc6eebfe4366d6763d75b8f148944 | |
parent | 43773eb3c4e9e5477076dcc2e314f72bda207c2d (diff) | |
download | lua-language-server-336eaae1db339f29b177aaa5fd05c46e4bde7368.zip |
no relationship between binaries and scripts
-rw-r--r-- | main.lua | 8 | ||||
-rw-r--r-- | make/bootstrap.lua | 43 |
2 files changed, 33 insertions, 18 deletions
@@ -1,4 +1,4 @@ -local fs = require 'bee.filesystem' +local fs = require 'bee.filesystem' local util = require 'utility' local version = require 'version' @@ -25,7 +25,9 @@ end loadArgs() -local rootPath = fs.exe_path():parent_path():parent_path():parent_path():string() +local currentPath = debug.getinfo(1, 'S').source:sub(2) +local rootPath = currentPath:gsub('[/\\]*[^/\\]-$', '') +rootPath = (rootPath == '' and '.' or rootPath) ROOT = fs.path(util.expandPath(rootPath)) LOGPATH = LOGPATH and util.expandPath(LOGPATH) or (ROOT:string() .. '/log') METAPATH = METAPATH and util.expandPath(METAPATH) or (ROOT:string() .. '/meta') @@ -46,7 +48,7 @@ log.debug('VERSION:', version.getVersion()) require 'tracy' -xpcall(dofile, log.debug, rootPath .. '/debugger.lua') +xpcall(dofile, log.debug, ROOT / 'debugger.lua') local service = require 'service' diff --git a/make/bootstrap.lua b/make/bootstrap.lua index 43dcdf5f..d379f599 100644 --- a/make/bootstrap.lua +++ b/make/bootstrap.lua @@ -34,29 +34,42 @@ else end
local root; do
- local sep = package.config:sub(1,1)
- if sep == '\\' then
- sep = '/\\'
+ if main then
+ local fs = require 'bee.filesystem'
+ local mainPath = fs.path(arg[0])
+ root = mainPath:parent_path():string()
+ if root == '' then
+ root = '.'
+ end
+ else
+ local sep = package.config:sub(1,1)
+ if sep == '\\' then
+ sep = '/\\'
+ end
+ local pattern = "["..sep.."][^"..sep.."]+"
+ root = package.cpath:match("([^;]+)"..pattern..pattern..pattern.."$")
end
- local pattern = "["..sep.."][^"..sep.."]+"
- root = package.cpath:match("([^;]+)"..pattern..pattern..pattern.."$")
end
-local fs = require 'bee.filesystem'
-fs.current_path(fs.path(root))
package.path = table.concat({
- "script/?.lua",
- "script/?/init.lua",
+ root .. "/script/?.lua",
+ root .. "/script/?/init.lua",
}, ";"):gsub('/', package.config:sub(1,1))
-loadfile = function (name)
- local f, e = io.open(root .. '/' .. name)
- if not f then
- return false, e
+package.searchers[2] = function (name)
+ local filename, err = package.searchpath(name, package.path)
+ if not filename then
+ return err
end
- local content = f:read 'a'
+ local f = io.open(filename)
+ local buf = f:read '*a'
f:close()
- return load(content, '@' .. name)
+ local relative = filename:sub(#root + 2)
+ local init, err = load(buf, '@' .. relative)
+ if not init then
+ return err
+ end
+ return init, filename
end
assert(loadfile(arg[0]))(table.unpack(arg))
|