mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-12 03:00:30 +00:00
Ensure require is usable within the REPL
As 'require' operates relative to the current program's directory, rather than the current directory, it meant we were trying to load files from /rom/programs. This is never a good idea, so we add the current directory to the package path, allowing you to use require as one'd expect.
This commit is contained in:
parent
9048deeb95
commit
0cb659d78c
@ -18,6 +18,23 @@ local tEnv = {
|
|||||||
}
|
}
|
||||||
setmetatable( tEnv, { __index = _ENV } )
|
setmetatable( tEnv, { __index = _ENV } )
|
||||||
|
|
||||||
|
-- Replace our package.path, so that it loads from the current directory, rather
|
||||||
|
-- than from /rom/programs. This makes it a little more friendly to use and
|
||||||
|
-- closer to what you'd expect.
|
||||||
|
do
|
||||||
|
local dir = shell.dir()
|
||||||
|
if dir:sub(1, 1) ~= "/" then dir = "/" .. dir end
|
||||||
|
if dir:sub(-1) ~= "/" then dir = dir .. "/" end
|
||||||
|
|
||||||
|
local strip_path = "?;?.lua;?/init.lua;"
|
||||||
|
local path = package.path
|
||||||
|
if path:sub(1, #strip_path) == strip_path then
|
||||||
|
path = path:sub(#strip_path + 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
package.path = dir .. "?;" .. dir .. "?.lua;" .. dir .. "?/init.lua;" .. path
|
||||||
|
end
|
||||||
|
|
||||||
if term.isColour() then
|
if term.isColour() then
|
||||||
term.setTextColour( colours.yellow )
|
term.setTextColour( colours.yellow )
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user