201 posts
Location
United Kingdom
Posted 11 March 2012 - 04:44 PM
[left]Hi, just a quick question; how do the functions 'shell.resolve()' and 'shell.resolveProgram()' work, what do they do, and how do I use them?[/left]
[left]Thanks![/left]
724 posts
Posted 11 March 2012 - 05:08 PM
look at the shell program
Spoiler
function shell.resolve( _sPath )
local sStartChar = string.sub( _sPath, 1, 1 )
if sStartChar == "/" or sStartChar == "" then
return fs.combine( "", _sPath )
else
return fs.combine( sDir, _sPath )
end
end
function shell.resolveProgram( _sCommand )
-- Substitute aliases firsts
if tAliases[ _sCommand ] ~= nil then
_sCommand = tAliases[ _sCommand ]
end
-- If the path is a global path, use it directly
local sStartChar = string.sub( _sCommand, 1, 1 )
if sStartChar == "/" or sStartChar == "" then
local sPath = fs.combine( "", _sCommand )
if fs.exists( sPath ) and not fs.isDir( sPath ) then
return sPath
end
return nil
end
-- Otherwise, look on the path variable
for sPath in string.gmatch(sPath, "[^:]+") do
sPath = fs.combine( shell.resolve( sPath ), _sCommand )
if fs.exists( sPath ) and not fs.isDir( sPath ) then
return sPath
end
end
-- Not found
return nil
end
715 posts
Posted 11 March 2012 - 05:11 PM
shell.resolve( localpath ) - returns the absolute path of the
localpath you provided.
shell.resolveProgram( name ) - returns the absolute path to the program whose
name you provided.
For example:
shell.resolve( "myFolder/file" )
If you call this while being in "/abcd/xyz/" and there is "myFolder/file" in there, then the above will return "/abcd/xyz/myFolder/file".
shell.resolveProgram( "dj" )
This will return "/rom/programs/dj".
201 posts
Location
United Kingdom
Posted 11 March 2012 - 05:26 PM
shell.resolve( localpath ) - returns the absolute path of the
localpath you provided.
shell.resolveProgram( name ) - returns the absolute path to the program whose
name you provided.
For example:
shell.resolve( "myFolder/file" )
If you call this while being in "/abcd/xyz/" and there is "myFolder/file" in there, then the above will return "/abcd/xyz/myFolder/file".
shell.resolveProgram( "dj" )
This will return "/rom/programs/dj".
Okay, thanks a lot for your quick reply!