1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-12 19:20:29 +00:00

Merge pull request #211 from Lignum/shell-run-lua

Make shell.resolveProgram pick up on *.lua files
This commit is contained in:
Daniel Ratcliffe 2017-05-07 17:33:44 +01:00 committed by GitHub
commit 6fba381a4e

View File

@ -111,6 +111,16 @@ function shell.resolve( _sPath )
end
end
local function pathWithExtension( _sPath, _sExt )
local nLen = #sPath
local sEndChar = string.sub( _sPath, nLen, nLen )
-- Remove any trailing slashes so we can add an extension to the path safely
if sEndChar == "/" or sEndChar == "\\" then
_sPath = string.sub( _sPath, 1, nLen - 1 )
end
return _sPath .. "." .. _sExt
end
function shell.resolveProgram( _sCommand )
-- Substitute aliases firsts
if tAliases[ _sCommand ] ~= nil then
@ -123,7 +133,12 @@ function shell.resolveProgram( _sCommand )
local sPath = fs.combine( "", _sCommand )
if fs.exists( sPath ) and not fs.isDir( sPath ) then
return sPath
end
else
local sPathLua = pathWithExtension( sPath, "lua" )
if fs.exists( sPathLua ) and not fs.isDir( sPathLua ) then
return sPathLua
end
end
return nil
end
@ -132,7 +147,12 @@ function shell.resolveProgram( _sCommand )
sPath = fs.combine( shell.resolve( sPath ), _sCommand )
if fs.exists( sPath ) and not fs.isDir( sPath ) then
return sPath
end
else
local sPathLua = pathWithExtension( sPath, "lua" )
if fs.exists( sPathLua ) and not fs.isDir( sPathLua ) then
return sPathLua
end
end
end
-- Not found