Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/argcheck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonan Collobert <ronan@collobert.com>2014-03-04 18:37:34 +0400
committerRonan Collobert <ronan@collobert.com>2014-03-04 18:37:34 +0400
commit88335e2b18ff364557fa15c494e7efcbcc688288 (patch)
tree032a755f027ccba601a1f795c0de0cb376e4f3ce /README.md
parent20320d8985ad5626d30c20d06d0af7093b39683d (diff)
doc: advanced usage
Diffstat (limited to 'README.md')
-rw-r--r--README.md19
1 files changed, 19 insertions, 0 deletions
diff --git a/README.md b/README.md
index 5bb6a37..9aaf96a 100644
--- a/README.md
+++ b/README.md
@@ -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.