cc.expect

The cc.expect library provides helper functions for verifying that function arguments are well-formed and of the correct type.

Usage

Changes

expect(index, value, ...)Expect an argument to have a specific type.
field(tbl, index, ...)Expect an field to have a specific type.
range(num, min, max)Expect a number to be within a specific range.
expect(index, value, ...)Source

Expect an argument to have a specific type.

Parameters

  1. index number The 1-based argument index.
  2. value The argument's value.
  3. ... string The allowed types of the argument.

Returns

  1. The given value.

Throws

  • If the value is not one of the allowed types.

field(tbl, index, ...)Source

Expect an field to have a specific type.

Parameters

  1. tbl table The table to index.
  2. index string The field name to check.
  3. ... string The allowed types of the argument.

Returns

  1. The contents of the given field.

Throws

  • If the field is not one of the allowed types.

range(num, min, max)Source

Expect a number to be within a specific range.

Parameters

  1. num number The value to check.
  2. min number The minimum value, if nil then -math.huge is used.
  3. max number The maximum value, if nil then math.huge is used.

Returns

  1. The given value.

Throws

  • If the value is outside of the allowed range.

Changes

  • New in version 1.96.0