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 /runtime/doc | |
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 'runtime/doc')
-rw-r--r-- | runtime/doc/builtin.txt | 12 | ||||
-rw-r--r-- | runtime/doc/usr_41.txt | 1 |
2 files changed, 13 insertions, 0 deletions
diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt index 99bc9e2be7..2364547937 100644 --- a/runtime/doc/builtin.txt +++ b/runtime/doc/builtin.txt @@ -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 diff --git a/runtime/doc/usr_41.txt b/runtime/doc/usr_41.txt index 2112fbb1b4..d5aa79e317 100644 --- a/runtime/doc/usr_41.txt +++ b/runtime/doc/usr_41.txt @@ -877,6 +877,7 @@ Other computation: *bitwise-function* srand() initialize seed used by rand() Variables: *var-functions* + instanceof() check if a variable is an instance of a given class type() type of a variable as a number typename() type of a variable as text islocked() check if a variable is locked |