Table.empty

From Multi Theft Auto: Wiki
Revision as of 11:29, 13 May 2012 by Kenix1 (talk | contribs) (Created page with "{{Useful Function}} <lowercasetitle></lowercasetitle> __NOTOC__ This function check is empty table or not. ==Syntax== <syntaxhighlight lang="lua">boolean table.empty( table a )</syntaxhighlight> ===Requi...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This function check is empty table or not.

Syntax

boolean table.empty( table a )

Required Arguments

  • a: The table to check is empty table or not.

Returns

Returns the true if table is empty or false in otherwise.

Click to collapse [-]
Code
function table.empty( a )
    if type( a ) ~= "table" then
        return false
    end
    
    return not next( a )
end
Click to collapse [-]
Example
print( 'empty = ' .. tostring( table.empty { [0] = 1 } ) ) -- false
print( 'empty = ' .. tostring( table.empty { [10] = 10, [2] = 2 } ) ) -- false
print( 'empty = ' .. tostring( table.empty { } ) ) -- true