Code Monkey home page Code Monkey logo

tcheck's Introduction

tcheck

A pure Lua module with no external dependency that provides simple sanity-checks of types for values. It doesn't aim to turn Lua into a typed language or anything fancy, it's just basically the equivalent of the luaL_check... functions in the Lua/C API that you will typically want to have at least on your public functions.

Install

Via Luarocks:

$ luarocks install tcheck

Or simply copy the single tcheck.lua file in your project or your LUA_PATH.

API

Assuming local tcheck = require 'tcheck'. You can check out the tests for actual examples of using the API.

tcheck(types, ...) or tcheck.check(types, ...)

Checks that the values conform to the types provided as first argument. The types argument can be a single string for a single value, or an array of strings.

The type string can be any of the type built-in function values, any of the math.type or io.type values, or a value to match with the __name or __type field of the value's metadata.

To support multiple types for a value, the pipe | character is used to separate different type names. As a special case, * can be specified to mean any non-nil value, it cannot be combined with any other type.

Returns the array of type names that did match for each value, or raises an error if a value did not match.

Development

Clone the project and install the required development dependencies:

  • luaunit (unit test runner)
  • luacov (recommended, test coverage)

If like me you prefer to keep your dependencies locally, per-project, then I recommend using my llrocks wrapper of the luarocks cli, which by default uses a local lua_modules/ tree.

$ llrocks install ...

To run tests:

$ llrocks run test/main.lua

To view code coverage:

$ llrocks cover test/main.lua

License

The BSD 3-clause license.

tcheck's People

Contributors

mna avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.