diff options
author | LemonBoy <thatlemon@gmail.com> | 2023-08-23 21:08:11 +0200 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2023-08-23 21:08:11 +0200 |
commit | afe0466fb1695fa8b9782eea8a8e9f9540d4cb85 (patch) | |
tree | f71446a214e45f7c0cdcb186fe40d25d1a1da39d /src/typval.c | |
parent | 1193951bebcff50d88403ce17dec5d3be14f131d (diff) |
patch 9.0.1786: Vim9: need instanceof() functionv9.0.1786
Problem: Vim9: need instanceof() function
Solution: Implement instanceof() builtin
Implemented in the same form as Python's isinstance because it allows
for checking multiple class types at the same time.
closes: #12867
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: LemonBoy <thatlemon@gmail.com>
Diffstat (limited to 'src/typval.c')
-rw-r--r-- | src/typval.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/typval.c b/src/typval.c index a760f356bf..e8aebee546 100644 --- a/src/typval.c +++ b/src/typval.c @@ -974,6 +974,34 @@ check_for_opt_buffer_or_dict_arg(typval_T *args, int idx) } /* + * Give an error and return FAIL unless "args[idx]" is an object. + */ + int +check_for_object_arg(typval_T *args, int idx) +{ + if (args[idx].v_type != VAR_OBJECT) + { + semsg(_(e_object_required_for_argument_nr), idx + 1); + return FAIL; + } + return OK; +} + +/* + * Give an error and return FAIL unless "args[idx]" is a class or a list. + */ + int +check_for_class_or_list_arg(typval_T *args, int idx) +{ + if (args[idx].v_type != VAR_CLASS && args[idx].v_type != VAR_LIST) + { + semsg(_(e_list_or_class_required_for_argument_nr), idx + 1); + return FAIL; + } + return OK; +} + +/* * Get the string value of a variable. * If it is a Number variable, the number is converted into a string. * tv_get_string() uses a single, static buffer. YOU CAN ONLY USE IT ONCE! |