patch 9.0.1786: Vim9: need instanceof() function
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>
diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt
index 99bc9e2..2364547 100644
--- a/runtime/doc/builtin.txt
+++ b/runtime/doc/builtin.txt
@@ -310,6 +310,7 @@
inputsave() Number save and clear typeahead
inputsecret({prompt} [, {text}]) String like input() but hiding the text
insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
+instanceof({object}, {class}) Number |TRUE| if {object} is an instance of {class}
interrupt() none interrupt script execution
invert({expr}) Number bitwise invert
isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
@@ -5052,6 +5053,17 @@
Can also be used as a |method|: >
mylist->insert(item)
+instanceof({object}, {class}) *instanceof()*
+ The result is a Number, which is |TRUE| when the {object} argument is a
+ direct or indirect instance of a |Class| specified by {class}.
+ When {class} is a |List| the function returns |TRUE| when {object} is an
+ instance of any of the specified classes.
+ Example: >
+ instanceof(animal, [Dog, Cat])
+
+< Can also be used as a |method|: >
+ myobj->instanceof(mytype)
+
interrupt() *interrupt()*
Interrupt script execution. It works more or less like the
user typing CTRL-C, most commands won't execute and control