lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On 2017-07-08 12:45 AM, Gary V. Vaughan wrote:
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.

    ```lua
    local my_function = argscheck "my_function (int, int) => int" ..
    function (a, b)
      return a + b
    end
    ```

Why not pow decorators?

x + argscheck "my_function (int, int) => int" .. f --> runtime error
x + argscheck '...' ^ f --> ok

In any case, both operators are right-associative, which gives proper decorator semantics.

(Also please tell me you felt inspired by my own libs? ^-^ [1][2])


- New `check` method for ensuring that a single value matches a given type specifier.

- New "functor" type specifier for matching objects with a `__call` metamethod - note, most `std.object` derived types will match successfully against the "functor" specifier.

- New "callable" type specifier for matching both objects with a `__call` metamethod, and objects for which Lua `type` returns "function" - note, this is exactly what the "function" specifier used to do.

Does this work in sandboxes?


### Bug fixes

- `argerror` and `resulterror` pass level 0 argument through to `error` to suppress file and line number prefix to error message.

### Incompatible changes

- The "function" (and "func") type specifiers no longer match objects with a `__call` metamethod. Use the new "callable" type specifier to match both types in the way that "function" used to, including most `std.object` derived types.

- Rather than a hardcoded `typecheck._VERSION` string, install a generated `typecheck.version` module, and autoload it on reference.

Install it with LuaRocks, using:

``` bash
    luarocks install typecheck 1.1
```


[1] http://marc.info/?l=lua-l&m=148755896416687&w=2
[2] http://marc.info/?l=lua-l&m=148745285529221&w=2

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.