Module luarocks.type_check
Type-checking functions. Functions and definitions for doing a basic lint check on files loaded by LuaRocks.
Functions
type_check_item (name, item, expected, context) | Type check an object. |
type_check_manifest (manifest) | Type check a manifest table. |
type_check_rockspec (rockspec) | Type check a rockspec table. |
type_check_table (tbl, types, context) | Type check the contents of a table. |
Functions
- type_check_item (name, item, expected, context)
-
Type check an object. The object is compared against an archetypical value matching the expected type -- the actual values don't matter, only their types. Tables are type checked recursively.
Parameters
- name: any: The object name (for error messages).
- item: any: The object being checked.
- expected: any: The reference object. In case of a table, its is structured as a type reference table.
- context:
Return value:
boolean or (nil, string): true if type checking succeeded, or nil and an error message if it failed.See also:
- type_check_manifest (manifest)
-
Type check a manifest table. Verify the correctness of elements from a manifest table, reporting on unknown fields and type mismatches.
Parameters
- manifest:
Return value:
boolean or (nil, string): true if type checking succeeded, or nil and an error message if it failed. - type_check_rockspec (rockspec)
-
Type check a rockspec table. Verify the correctness of elements from a rockspec table, reporting on unknown fields and type mismatches.
Parameters
- rockspec:
Return value:
boolean or (nil, string): true if type checking succeeded, or nil and an error message if it failed. - type_check_table (tbl, types, context)
-
Type check the contents of a table. The table's contents are compared against a reference table, which contains the recognized fields, with archetypical values matching the expected types -- the actual values of items in the reference table don't matter, only their types (ie, for field x in tbl that is correctly typed, type(tbl.x) == type(types.x)). If the reference table contains a field called MORE, then unknown fields in the checked table are accepted. If it contains a field called ANY, then its type will be used to check any unknown fields. If a field is prefixed with MUST_, it is mandatory; its absence from the table is a type error. Tables are type checked recursively.
Parameters
- tbl: table: The table to be type checked.
- types: table: The reference table, containing values for recognized fields in the checked table.
- context:
Return value:
boolean or (nil, string): true if type checking succeeded, or nil and an error message if it failed.