tableize
function tableize( val ) --> tab
Description
Puts val in a table if it is necessary. If val is a table return the function just val.
Parameters
- val
-
The value that should be a table.
Return Values
- tab
-
A table with val as value or val itself when it is a table.
Code
--ZFUNC-tableize-v1 local function tableize( val ) --> tab if type( val ) == "table" then return val else return { val } end end return tableize
Examples
local t = require( "taptest" ) local same = require( "same" ) local tableize = require( "tableize" ) t( same( tableize( "root" ), { "root" } ), true ) t( same( tableize{ "root" }, { "root" } ), true ) t( same( tableize( 1 ), { 1 } ), true ) t( same( tableize(), {} ), true ) t( same( tableize( nil ), {} ), true ) t()