MTA:Eir/FileSystem/translator/relPath: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ This function transform a path that is passed to it into a path that is relative to the translators current directory. The path must be accessible from the translator. ...")
 
mNo edit summary
 
Line 4: Line 4:
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
string translator.relPath ( string path )
string translator:relPath ( string path )
</syntaxhighlight>
</syntaxhighlight>


Line 19: Line 19:
local function getPathTranslatorRelative( srcTranslator, dstTranslator, srcPath )
local function getPathTranslatorRelative( srcTranslator, dstTranslator, srcPath )
     -- Get the absolute path from the srcTranslator perspective.
     -- Get the absolute path from the srcTranslator perspective.
     local absPath = srcTranslator.absPath( srcPath );
     local absPath = srcTranslator:absPath( srcPath );


     -- Return the relative path from the dstTranslator. Will return false if conversion cannot happen.
     -- Return the relative path from the dstTranslator. Will return false if conversion cannot happen.
     return dstTranslator.relPath( absPath );
     return dstTranslator:relPath( absPath );
end
end
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>
{{:MTA:Eir/FileSystem/translator/functions}}
{{:MTA:Eir/FileSystem/translator/functions}}

Latest revision as of 23:26, 16 January 2022

This function transform a path that is passed to it into a path that is relative to the translators current directory. The path must be accessible from the translator. The path can either be absolute or relative.

Syntax

string translator:relPath ( string path )

Arguments

  • path: the path that should be transformed into a relative path; can be nil if the current directory should be returned

Returns

This function returns the relative version of the path that is passed to it, false if the specified path is not accessible by the translator.

Example

Click to collapse [-]
Client

This snippet converts the path relative from one translator to a relative path from another translator.

local function getPathTranslatorRelative( srcTranslator, dstTranslator, srcPath )
    -- Get the absolute path from the srcTranslator perspective.
    local absPath = srcTranslator:absPath( srcPath );

    -- Return the relative path from the dstTranslator. Will return false if conversion cannot happen.
    return dstTranslator:relPath( absPath );
end

FileSystem Translator Functions