(Original) cocos2d-x 3.0 + Lua learning and working (4): common functions (2): Check

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.