1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-09-28 15:08:47 +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
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 ) function shell.resolveProgram( _sCommand )
-- Substitute aliases firsts -- Substitute aliases firsts
if tAliases[ _sCommand ] ~= nil then if tAliases[ _sCommand ] ~= nil then
@ -123,7 +133,12 @@ function shell.resolveProgram( _sCommand )
local sPath = fs.combine( "", _sCommand ) local sPath = fs.combine( "", _sCommand )
if fs.exists( sPath ) and not fs.isDir( sPath ) then if fs.exists( sPath ) and not fs.isDir( sPath ) then
return sPath 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 return nil
end end
@ -132,7 +147,12 @@ function shell.resolveProgram( _sCommand )
sPath = fs.combine( shell.resolve( sPath ), _sCommand ) sPath = fs.combine( shell.resolve( sPath ), _sCommand )
if fs.exists( sPath ) and not fs.isDir( sPath ) then if fs.exists( sPath ) and not fs.isDir( sPath ) then
return sPath return sPath
end else
local sPathLua = pathWithExtension( sPath, "lua" )
if fs.exists( sPathLua ) and not fs.isDir( sPathLua ) then
return sPathLua
end
end
end end
-- Not found -- Not found