caddr
function caddr( arr ) --> val
Description
Returns the third value of an array table. Useful for methods with multiple return values.
Parameters
- arr
-
An array table with three or more values.
Return Values
- val
-
The third value from arr, if no third value exist returns the function nil.
Code
--ZFUNC-caddr-v1 local function caddr( arr ) --> val if not arr then return nil end return arr[ 3 ] end return caddr
Examples
local t = require( "taptest" ) local caddr = require( "caddr" ) local function beatles() return "John", "Paul", "George", "Ringo" end t( caddr(), nil ) t( caddr{ 1.0 }, nil ) t( caddr{ "a", "b" }, nil ) t( caddr{ "a", "b", "c" }, "c" ) t( caddr{ beatles() }, "George" ) t()