luatypechecks, v1.2.0
Posted on

The library that implements various type checks in order to simulate static typing in the Lua language.
Added checks for the presence of metamethods and regular methods; added switchable analogues of the assert() function; supplemented the documentation with descriptions of functions that are not obvious.
Note that this library isn't designed to validate input data, but only to simulate static typing for function parameters.
Disclaimer: this library was written directly on an Android smartphone with the QLua IDE.
Change Log
- checking:
- checks:
- method checks:
checks.has_metamethods(value, metamethod_names);checks.has_methods(value, method_names);checks.has_methods_anywhere(value, method_names);
- method checks:
- for each check:
- there is a variant that allows the value
nil—checks.has_*_or_is_nil(value, ...);
- there is a variant that allows the value
- checks:
- asserting:
- assertions:
assertions.is_true(value);assertions.is_false(value);
- assertions:
- supplemented the documentation with descriptions of functions that are not obvious.
Features
- checking:
- checks:
checks.is_boolean(value);checks.is_number(value):checks.is_integer(value);
checks.is_string(value);checks.is_function(value):checks.is_callable(value);
checks.is_table(value[, key_checker[, value_checker[, deep_checks_mode="with_deep_checks"]]]):checks.is_sequence(value[, value_checker[, deep_checks_mode="with_deep_checks"]]);
checks.is_enumeration(value, enumeration);- method checks:
checks.has_metamethods(value, metamethod_names);checks.has_methods(value, method_names);checks.has_methods_anywhere(value, method_names);
checks.is_instance(value, class);
- for each check:
- there is a variant that allows the value
nil—checks.is_*_or_nil(value, ...)/checks.has_*_or_is_nil(value, ...); - if the check accepts additional parameters, there is a constructor that creates a closure with these parameters (i.e., performs currying) —
checks.make_*_checker(...);
- there is a variant that allows the value
- checks:
- asserting:
- assertions:
assertions.is_true(value);assertions.is_false(value);
- for each check, there is a variant wrapped in an
assert()function call — see packageassertions;
- assertions:
- optimization:
- it's possible to disable checking of table key types and table value types:
- individually for a particular check;
- globally for the whole package
checks;
- it's possible to disable asserting globally for the whole package
assertions.
- it's possible to disable checking of table key types and table value types:
Repository
Link: https://github.com/thewizardplusplus/luatypechecks/tree/v1.2.0.
Content: code.
License: MIT.