🟧ArgAssert

Function of validation of input types of arguments to the function.

gpm.ArgAssert( any value, number argNum, string expected, number errorlevel )

The function is available by default in the gpm package environment, so just call ArgAssert instead of gpm.ArgAssert

Accept any type names from Enums/TYPE and custom type names created by gpm.AddType.

Example Usage

function string.Mult( str, count)
    gpm.ArgAssert( str, 1, "string" )
    gpm.ArgAssert( count, 2, "number" )

    local output = ""
    for i = 1, count do
        output = output .. str
    end

    return output
end

print( string.Mult( "123", 5 ) )
-- 123123123123123

print( string.Mult( 123, 5 ) )
-- packages/fractions.lua:121: bad argument #1 to 'Mult' (string expected, got number)

Last updated