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

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
Line 4: Line 4:
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
string translator.absPathRoot ( string path )
string translator:absPathRoot ( string path )
</syntaxhighlight>
</syntaxhighlight>


Line 22: Line 22:
-- Create our utility function.
-- Create our utility function.
local function isPathValidForResource( path )
local function isPathValidForResource( path )
     return not ( resRoot.absPathRoot( path ) == false );
     return not ( resRoot:absPathRoot( path ) == false );
end
end



Latest revision as of 23:27, 16 January 2022

This function resolves a specified path into its absolute version. The path is resolved from the translator root. This function can be used to get a unique version of a path (without scripting symbols such as '..').

Syntax

string translator:absPathRoot ( string path )

Arguments

  • path: the path that should be resolved into an absolute path; can be nil to return the absolute location of the translator (on host filesystems such as NTFS or ext3)

Returns

This function returns the absolute 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 checks whether the path given to it is valid for the resource.

-- Get a handle to the resource instance directory.
local resRoot = fileCreateTranslator( "/" );

-- Create our utility function.
local function isPathValidForResource( path )
    return not ( resRoot:absPathRoot( path ) == false );
end

-- Is the path inside of/valid for our resource? Should return false.
local myPathValidity = isPathValidForResource( "C:/Windows/System32/" );

outputChatBox( "the windows system directory is " .. ( myPathValidity and "" or "not " ) .. "valid." );

FileSystem Translator Functions