Lua 5.3 - Integers - type() - lua_type()

Viewed 3052

Since Lua 5.3, inegers are supported.

But how can I do :

if type( 123 ) == "integer" then
end

Or

switch( lua_type( L, -1 ) )
{
case LUA_TINTEGER:
    break;
}

Since type() is still going to return "number" for both integer and reals, and LUA_TINTEGER does not exist ?

Thanks.

3 Answers
--  Lua 5.3 'type' replacement. by m2mm4m
    local typeRaw=type;
    local typeNew=function(I_vValue)
        local LR_sType;
        local L_tyRaw=typeRaw(I_vValue);
        if(L_tyRaw=="number")then
            LR_sType=maths.type(I_vValue);
        else
            LR_sType=L_tyRaw;
        end
        return LR_sType;
    end
--  _G.type=typeNew;    --    Over ride global.
    assert(typeNew(123)=="integer",     "Error with 'typeNew'.");
    assert(typeNew(123.456)=="float",   "Error with 'typeNew'.");
    assert(typeNew("123.456")=="string","Error with 'typeNew'.");
    assert(typeNew(nil)=="nil",          "Error with 'typeNew'.");
Related