diff options
author | Ronan Collobert <ronan@collobert.com> | 2014-03-04 18:37:34 +0400 |
---|---|---|
committer | Ronan Collobert <ronan@collobert.com> | 2014-03-04 18:37:34 +0400 |
commit | 88335e2b18ff364557fa15c494e7efcbcc688288 (patch) | |
tree | 032a755f027ccba601a1f795c0de0cb376e4f3ce /README.md | |
parent | 20320d8985ad5626d30c20d06d0af7093b39683d (diff) |
doc: advanced usage
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -362,3 +362,22 @@ end ``` As you can see, for a simple example like this one, the code is already not that trivial. + +### Advanced usage + +By default, `argcheck` uses the standard `type()` Lua function to determine the type of your +arguments. In some cases, like if you are handling your own class system, you might want to +specify how to check types. This can be simply done by overriding the `isoftype()` function +available in the `argcheck` environment. +```lua +env = require 'argcheck.env' -- retrieve argcheck environement + +-- this is the default type function +-- which can be overrided by the user +function env.isoftype(obj, typename) + return type(obj) == typename +end +``` +Note that if you change the `isoftype()` function, it will *not* affect previously defined +argument checking functions: `isoftype()` is passed as an upvalue for each created argument +function. |