[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [ANN] validate.args - validate function arguments
- From: Fabien <fleutot+lua@...>
- Date: Sat, 14 May 2011 00:16:39 +0200
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.