lua-users home
lua-l archive

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

Here's another take on argument validation, written in C. It focuses on being unobtrusive in the code, rather than offering very sophisticated validation options. When a function is called with incorrect parameters, it will produce an error formatted as those produced by the plain Lua checking APIs "luaL_checkxxx(L, idx)".

The file is self-sufficient; its usage is described in its first comment block; it is available under the MIT licence.

In a nutshell, if a function expects as arguments a number, followed by an optional string, then finally either a table or a boolean, it can be protected by calling:

checks('number', '?string', 'table|boolean')

Some mechanisms are provided to define custom type names, in addition to the built-in ones.

On Fri, May 13, 2011 at 7:18 PM, Diab Jerius <> wrote:
validate.args provides facilities to validate arguments to functions.
It provides a basic set of validation constraints which can be expanded
upon. It understands positional and named arguments.

A rockspec and a complete tarball are available here: