aboutsummaryrefslogtreecommitdiff
path: root/runtime/doc/if_lua.txt
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2019-11-10 22:18:59 -0800
committerJustin M. Keyes <justinkz@gmail.com>2019-11-10 23:43:49 -0800
commita0d992785feeefaea2810dcf08564fd8bea8cab9 (patch)
tree2fe3e78189b0e3dc34e86ec64984da604e3a480a /runtime/doc/if_lua.txt
parent7aa4042d3bddf2f39d048b9ba1dd7adf2193d4eb (diff)
downloadrneovim-a0d992785feeefaea2810dcf08564fd8bea8cab9.tar.gz
rneovim-a0d992785feeefaea2810dcf08564fd8bea8cab9.tar.bz2
rneovim-a0d992785feeefaea2810dcf08564fd8bea8cab9.zip
Lua: Use vim.validate() instead of assert()
Diffstat (limited to 'runtime/doc/if_lua.txt')
-rw-r--r--runtime/doc/if_lua.txt59
1 files changed, 59 insertions, 0 deletions
diff --git a/runtime/doc/if_lua.txt b/runtime/doc/if_lua.txt
index bba43ea32c..7eef5d3903 100644
--- a/runtime/doc/if_lua.txt
+++ b/runtime/doc/if_lua.txt
@@ -847,4 +847,63 @@ pesc({s}) *vim.pesc()*
See also: ~
https://github.com/rxi/lume
+validate({opt}) *vim.validate()*
+ Validates a parameter specification (types and values).
+
+ Usage example: >
+
+ function user.new(name, age, hobbies)
+ vim.validate{
+ name={name, 'string'},
+ age={age, 'number'},
+ hobbies={hobbies, 'table'},
+ }
+ ...
+ end
+<
+
+ Examples with explicit argument values (can be run directly): >
+
+ vim.validate{arg1={{'foo'}, 'table'}, arg2={'foo', 'string'}}
+ => NOP (success)
+<
+>
+ vim.validate{arg1={1, 'table'}}
+ => error('arg1: expected table, got number')
+<
+>
+ vim.validate{arg1={3, function(a) return (a % 2) == 0 end, 'even number'}}
+ => error('arg1: expected even number, got 3')
+<
+
+ Parameters: ~
+ {opt} Map of parameter names to validations. Each key is
+ a parameter name; each value is a tuple in one of
+ these forms:
+ 1. (arg_value, type_name, optional)
+ • arg_value: argument value
+ • type_name: string type name, one of: ("table",
+ "t", "string", "s", "number", "n", "boolean",
+ "b", "function", "f", "nil", "thread",
+ "userdata")
+ • optional: (optional) boolean, if true, `nil`
+ is valid
+
+ 2. (arg_value, fn, msg)
+ • arg_value: argument value
+ • fn: any function accepting one argument,
+ returns true if and only if the argument is
+ valid
+ • msg: (optional) error string if validation
+ fails
+
+is_callable({f}) *vim.is_callable()*
+ Returns true if object `f` can be called as a function.
+
+ Parameters: ~
+ {f} Any object
+
+ Return: ~
+ true if `f` is callable, else false
+
vim:tw=78:ts=8:ft=help:norl: