Releases: gvvaughan/typecheck
[ANN] typecheck 3.0 released
I am happy to announce release 3.0 of typecheck.
The main purpose of this release is to consolidate and normalize API calls.
Typecheck's home page is at http://gvvaughan.github.io/typecheck
A Luaish run-time gradual type checking system, for argument and return types at function boundaries with simple annotations that can be disabled in production code. Its API and type mismatch errors are modelled on the core Lua C-language argcheck () API.
- Luaish: Type check failures show error messages in the same format as Lua itself;
- run time: Without changing any library code, the application can decide at run time whether to enable type checking as it loads the library;
- gradual: Type checks can be introduced to the functions in your code gradually, to as few or as many as seem useful;
- type checking: function argument types and return types are checked against the specification, and raise an error on mismatch.
This is a light-weight library for Lua 5.1 (including LuaJIT), 5.2, 5.3 and 5.4 written in pure Lua.
This code started life as the function argument and return type checking system I wrote for lua-stdlib. I’m still in the process of slimming down lua-stdlib in preparation for the next release though, part of which means that you can now use typecheck without requiring the installation of all of stdlib.
Noteworthy changes in release 3.0 (2023-01-31) [stable]
New Features
-
ARGCHECK_FRAMEis now exported for use when writing your own functions that need to adjust any stacklevelargument they support, rather than having to divine if from the internals of_debug.argcheck. -
Accept either of 'integer' or 'int' in an argcheck typespec.
-
When diagnosing a type mismatch, be specific about unexpected 'integer' or 'float' rather than just 'number'
bad argument #1 to 'getfenv' (integer expected, got float) -
Instead of diagnosing an argument mismatch against
?anyas 'expected any value or nil, got no value', we now get 'expected argument, got no value'. Similarly, for missing results for `?any' we now get 'expected result, go no value'. -
Support importing into another project directly with:
$ cp ../typecheck/lib/typecheck/init.lua lib/typecheck.lua
-
Multi-typed specifications are sorted asciibetically in error messages by
argerrorandresulterrorto make writing tests for typechecked functions easier.
Bug fixes
-
No matter whether 'int' or 'integer' is specified, always use 'integer' in error messages, for consistency with 'bool' as an alias of 'boolean'.
-
When 'table of int', 'list of funcs', 'table of bool' or similar are specified, consistently use 'table of integers', 'list of functions', 'table of booleans', etc.
-
argschecknow correctly diagnoses unexpectednilarguments with 'got nil', and missing arguments with 'got no value'. Likewise for result errors about unexpectednilresults and missing return values. -
Diagnose passing of incompatible objects with a
__tostringmetamethod to parameters that require a string instead of silently coercing to a string. -
Functable's are most definitely NOT functors as that term is used by functional programmers. The library will accept 'functor' as a synonym for backwards compatibility, but otherwise we now use the term functable everywhere to avoid confusion.
Incompatible changes
-
types.stringyis no longer available; silently converting any object passed to a string parameter by calling the__tostringmetamethod has unintended consequences for the function behaviour and behaves differently when typechecking is disabled and the conversion to string is consequently disabled.- If you know you want an argument converted to a string before passing to typechecked function, you should call
tostringon it at the call-site. - If you know you want tables with
__tostringmetamethods to be valid arguments, make the typespec 'string|table' and calltostringon it in your function.
- If you know you want an argument converted to a string before passing to typechecked function, you should call
-
Number-like string arguments are considered a mismatch for previously compatible expected number types for the same reason. As above, either call
tonumberat the call-site, or make the typespec 'number|string' and calltonumberinside your function. -
argcheck,argerror,argscheckandresulterrorno longer accept a table with a__tostringmetamethod as a substitute for an actual string for those parameters that require a string. -
extramsg_mismatchprovides more specific details when the expected argument is 'int' or 'integer':bad argument #1 to 'getfenv' (float has no integer representation)
Install it with LuaRocks, using:
luarocks install typecheck 3.0
[ANN] typecheck 2.1 released
I am happy to announce release 2.1 of typecheck.
The main purpose of this release is to introduce compatibility with Lua 5.4, and to scoop up some bug fixes that have been waiting for this overdue release.
Typecheck's home page is at http://gvvaughan.github.io/typecheck
A Luaish run-time gradual type checking system, for argument and return types at function boundaries with simple annotations that can be disabled in production code. Its API and type mismatch errors are modelled on the core Lua C-language argcheck () API.
- Luaish: Type check failures show error messages in the same format as Lua itself;
- run time: Without changing any library code, the application can decide at run time whether to enable type checking as it loads the library;
- gradual: Type checks can be introduced to the functions in your code gradually, to as few or as many as seem useful;
- type checking: function argument types and return types are checked against the specification, and raise an error on mismatch.
This is a light-weight library for Lua 5.1 (including LuaJIT), 5.2, 5.3 and 5.4 written in pure Lua.
This code started life as the function argument and return type checking system I wrote for lua-stdlib. I’m still in the process of slimming down lua-stdlib in preparation for the next release though, part of which means that you can now use typecheck without requiring the installation of all of stdlib.
Noteworthy changes in release 2.1 (2020-04-24) [stable]
New features
-
Initial support for Lua 5.4.
-
No longer depends on
std.normalize. -
No need to preinstall
std.strictfor deployment, of course that
means without runtime global variable checking. In development
environments,std.strictwill be loaded and used for runtime
checks as before.
Bug fixes
- works with std.strict again.
Install it with LuaRocks, using:
luarocks install typecheck 2.1[ANN] typecheck 2.0 released
I am happy to announce release 2.0 of typecheck.
The main purpose of this release is to replace configuration using a shared _DEBUG global variable with a dependency on the std._debug module: much more hygienic and interoperable, but breaking backwards compatibility (hence the major version number bump for a small change).
Typecheck's home page is at http://gvvaughan.github.io/typecheck
A Luaish run-time gradual type checking system, for argument and return types at function boundaries with simple annotations that can be disabled in production code. Its API and type mismatch errors are modelled on the core Lua C-language argcheck () API.
- Luaish: Type check failures show error messages in the same format as Lua itself;
- run time: Without changing any library code, the application can decide at run time whether to enable type checking as it loads the library;
- gradual: Type checks can be introduced to the functions in your code gradually, to as few or as many as seem useful;
- type checking: function argument types and return types are checked against the specification, and raise an error on mismatch.
This is a light-weight library for Lua 5.1 (including LuaJIT), 5.2 and 5.3 written in pure Lua.
This code started life as the function argument and return type checking system I wrote for lua-stdlib. I’m in the process of slimming down lua-stdlib in preparation for the next release though, part of which means that you can now use typecheck without requiring the installation of all of stdlib.
Noteworthy changes in release 2.0 (2018-01-15) [stable]
Incompatible changes
- Use
std._debughints to enable or disable runtime type checking instead of shared global_DEBUGsymbol.
Install it with LuaRocks, using:
luarocks install typecheck 1.1[ANN] typecheck 1.1 released
I am happy to announce release 1.1 of typecheck.
Typecheck's home page is at http://gvvaughan.github.io/typecheck
A Luaish run-time gradual type checking system, for argument and return types at function boundaries with simple annotations that can be disabled in production code. Its API and type mismatch errors are modelled on the core Lua C-language argcheck () API.
- Luaish: Type check failures show error messages in the same format as Lua itself;
- run time: Without changing any library code, the application can decide at run time whether to enable type checking as it loads the library;
- gradual: Type checks can be introduced to the functions in your code gradually, to as few or as many as seem useful;
- type checking: function argument types and return types are checked against the specification, and raise an error on mismatch.
This is a light-weight library for Lua 5.1 (including LuaJIT), 5.2 and 5.3 written in pure Lua.
This code started life as the function argument and return type checking system I wrote for lua-stdlib. I’m in the process of slimming down lua-stdlib in preparation for the next release though, part of which means that you can now use typecheck without requiring the installation of all of stdlib.
Noteworthy changes in release 1.1 (2017-07-07) [stable]
New features
-
Support type annotations with concat decorators.
local my_function = argscheck "my_function (int, int) => int" .. function (a, b) return a + b end
-
New
checkmethod for ensuring that a single value matches a given type specifier. -
New "functor" type specifier for matching objects with a
__callmetamethod - note, moststd.objectderived types will match successfully against the "functor" specifier. -
New "callable" type specifier for matching both objects with a
__callmetamethod, and objects for which Luatypereturns "function" - note, this is exactly what the "function" specifier used to do.
Bug fixes
argerrorandresulterrorpass level 0 argument through toerrorto suppress file and line number prefix to error message.
Incompatible changes
-
The "function" (and "func") type specifiers no longer match objects with a
__callmetamethod. Use the new "callable" type specifier to match both types in the way that "function" used to, including moststd.objectderived types. -
Rather than a hardcoded
typecheck._VERSIONstring, install a generatedtypecheck.versionmodule, and autoload it on reference.
Install it with LuaRocks, using:
luarocks install typecheck 1.1[ANN] typecheck-1.0 released
I am happy to announce release 1.0 of typecheck.
Typecheck's home page is at http://gvvaughan.github.io/typecheck
A Luaish run-time gradual type checking system, for argument and return types at function boundaries with simple annotations that can be disabled in production code. Its API and type mismatch errors are modelled on the core Lua C-language argcheck () API.
- Luaish: Type check failures show error messages in the same format as Lua itself;
- run time: Without changing any library code, the application can decide at run time whether to enable type checking as it loads the library;
- gradual: Type checks can be introduced to the functions in your code gradually, to as few or as many as seem useful;
- type checking: function argument types and return types are checked against the specification, and raise an error on mismatch.
This is a light-weight library for Lua 5.1 (including LuaJIT), 5.2 and 5.3 written in pure Lua.
This code started life as the function argument and return type checking system I wrote for lua-stdlib. I’m in the process of slimming down lua-stdlib in preparation for the next release though, part of which means that you can now use typecheck without requiring the installation of all of stdlib.
Noteworthy changes in release 1.0 (2016-01-25) [stable]
New features
- Initial release, now separated out from lua-stdlib.
Install it with LuaRocks, using:
luarocks install typecheck 1.0