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>
This commit is contained in:
LemonBoy
2023-08-23 21:08:11 +02:00
committed by Christian Brabandt
parent 1193951beb
commit afe0466fb1
13 changed files with 212 additions and 19 deletions

View File

@ -310,6 +310,7 @@ inputrestore() Number restore typeahead
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 @@ insert({object}, {item} [, {idx}]) *insert()*
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