Inspect: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (added image to example)
Line 7: Line 7:
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
string inspect ( mixed var )            
string inspect ( mixed var [, table options] )  
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''var:''' A variable of any datatype.
*'''var:''' A variable of any datatype.
*'''options:''' A table of options. It is not mandatory, but when it is provided, it must be a table. For a list of options, see the [https://github.com/kikito/inspect.lua#options Inspect's GitHub page].


===Returns===
===Returns===

Revision as of 12:06, 8 December 2017

This function returns human-readable representations of tables and MTA datatypes as a string.

Syntax

string inspect ( mixed var [, table options] )    

Required Arguments

  • var: A variable of any datatype.
  • options: A table of options. It is not mandatory, but when it is provided, it must be a table. For a list of options, see the Inspect's GitHub page.

Returns

Always returns a string.

Example

Click to collapse [-]
Client

This example draws the contents of a table and its data type:

local Table = {    
    ["matrix"] = {position = {getElementPosition(localPlayer)},rotation = {getElementRotation( localPlayer )}},
    ["localplayer"] = getPlayerName(localPlayer),
}

addEventHandler("onClientRender",root,
    function( )
        dxDrawText(inspect(Table),10,250)
    end
)

This is an example of what it should look like:

InspectReturn.png

See Also

Shared