The functions here are mainly used for checking operations. Reference: quick_cocos.
Xingyue's contribution ~~~
--[[-- 检查并转换为数值,转换失败则返回 0-- @param value 要检查并转换的值-- @param base 进制,默认为十进制-- @return number 返回的数值--]]function checkNumber( value, base ) return tonumber( value, base ) or 0end--[[-- 检查并转换为布尔值, 除了nil和false,其他任何值返回true-- @parame value 要检查的值-- @return boolean 返回布尔值--]]function checkBool( value ) return ( value ~= nil and value ~= false )end--[[-- 检查并转换为整数,转换失败则返回 0-- @param value 要检查的值-- @return integer 返回整数--]]function checkInt( value ) return math.floor( checkNumber( value ) )end--[[-- 检查是否是一个表格,如果不是则返回一个空表格-- @param value 要检查的值-- @return table 返回一个表格--]]function checkTable( value ) if type( value ) ~= "table" then value = {} end return valueend--[[-- 如果表格中指定 key 的值为 nil,或者输入值不是表格,返回false,否则返回true-- @param hashTable 要检查的表格-- @param key 要检查的键名-- @return boolean 返回布尔值--]] function isSet( hashTable, key ) local t = type( hashTable ) return ( t == "table" or t == "userdate" ) and hashTable[key] ~= nilend
The author uses cocos2d-x 3.0 + Lua learning and work experience, without the author's consent, please do not reprint! Thank you for your patience ~~~
This article is not approved by the author and cannot be reproduced. Otherwise, relevant responsibilities will be held accountable. For more information, see the source !!~~
Address: http://www.cnblogs.com/wodehao0808/p/4015648.html
(Original) cocos2d-x 3.0 + Lua learning and working (4): common functions (2): Check