diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2020-10-25 18:46:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-25 18:46:57 +0100 |
commit | c3ef19813293b0606eea68c924c5b611cdbf144b (patch) | |
tree | a97c09d911026429a4d66321321e778f8a054778 /src/nvim/api/private/helpers.c | |
parent | 6312792d8a6a7d293661d33d440343d4cc6e0e6e (diff) | |
parent | a83b76790b82c8f9e74b82c8b0061682b66ddd0d (diff) | |
download | rneovim-c3ef19813293b0606eea68c924c5b611cdbf144b.tar.gz rneovim-c3ef19813293b0606eea68c924c5b611cdbf144b.tar.bz2 rneovim-c3ef19813293b0606eea68c924c5b611cdbf144b.zip |
Merge pull request #13077 from tjdevries/tjdevries/buf_apis_1
api: nvim_buf_delete
Diffstat (limited to 'src/nvim/api/private/helpers.c')
-rw-r--r-- | src/nvim/api/private/helpers.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 84517c99fc..981d41ae6e 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -1619,14 +1619,24 @@ free_exit: return virt_text; } -bool api_is_truthy(Object obj, const char *what, bool nil_truthy, Error *err) +/// Force obj to bool. +/// If it fails, returns false and sets err +/// @param obj The object to coerce to a boolean +/// @param what The name of the object, used for error message +/// @param nil_value What to return if the type is nil. +/// @param err Set if there was an error in converting to a bool +bool api_coerce_to_bool( + Object obj, + const char *what, + bool nil_value, + Error *err) { if (obj.type == kObjectTypeBoolean) { return obj.data.boolean; } else if (obj.type == kObjectTypeInteger) { return obj.data.integer; // C semantics: non-zero int is true } else if (obj.type == kObjectTypeNil) { - return nil_truthy; // caller decides what NIL (missing retval in lua) means + return nil_value; // caller decides what NIL (missing retval in lua) means } else { api_set_error(err, kErrorTypeValidation, "%s is not an boolean", what); return false; |