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=-math.huge [, max=math.huge]])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=-math.huge [, max=math.huge]])Source

Expect a number to be within a specific range.

Parameters

  1. num number The value to check.
  2. min? number = -math.huge The minimum value.
  3. max? number = math.huge The maximum value.

Returns

  1. The given value.

Throws

  • If the value is outside of the allowed range.

Changes

  • New in version 1.96.0