Skip to content

Commit

Permalink
fixup: fixup: fixup: fixup:
Browse files Browse the repository at this point in the history
  • Loading branch information
tjdevries authored and skippi committed Oct 25, 2020
1 parent be44781 commit bf35c43
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/nvim/api/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -972,11 +972,11 @@ void nvim_buf_delete(Buffer buffer, Dictionary opts, Error *err)
bool unload = false;
for (size_t i = 0; i < opts.size; i++) {
String k = opts.items[i].key;
Object *v = &opts.items[i].value;
Object v = opts.items[i].value;
if (strequal("force", k.data)) {
force = api_coerce_to_bool(*v, "force", false, err);
force = api_coerce_to_bool(v, "force", false, err);
} else if (strequal("unload", k.data)) {
unload = api_coerce_to_bool(*v, "unload", false, err);
unload = api_coerce_to_bool(v, "unload", false, err);
} else {
api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data);
return;
Expand Down
16 changes: 10 additions & 6 deletions src/nvim/api/private/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1621,18 +1621,22 @@ VirtText parse_virt_text(Array chunks, 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 if_nil 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 if_nil, Error *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 if_nil; // 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;
Expand Down

0 comments on commit bf35c43

Please sign in to comment.