Skip to content

Commit

Permalink
string_eqeq
Browse files Browse the repository at this point in the history
  • Loading branch information
mhermier committed Mar 10, 2023
1 parent 3f268ff commit d896dc9
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/vm/wren_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,21 @@ DEF_PRIMITIVE(string_startsWith)
RETURN_BOOL(memcmp(string->value, search->value, search->length) == 0);
}

static bool string_eqeq(Value lhs, Value rhs) {
if (!IS_STRING(rhs)) return false;
return wrenStringEquals(AS_STRING(lhs), AS_STRING(rhs));
}

DEF_PRIMITIVE(string_eqeq)
{
RETURN_BOOL(string_eqeq(args[0], args[1]));
}

DEF_PRIMITIVE(string_bangeq)
{
RETURN_BOOL(!string_eqeq(args[0], args[1]));
}

DEF_PRIMITIVE(string_plus)
{
if (!validateString(vm, args[1], "Right operand")) return false;
Expand Down Expand Up @@ -1568,6 +1583,8 @@ void wrenInitializeCore(WrenVM* vm)
vm->stringClass = AS_CLASS(wrenFindVariable(vm, coreModule, "String"));
PRIMITIVE(vm->stringClass->obj.classObj, "fromCodePoint(_)", string_fromCodePoint);
PRIMITIVE(vm->stringClass->obj.classObj, "fromByte(_)", string_fromByte);
PRIMITIVE(vm->stringClass, "==(_)", string_eqeq);
PRIMITIVE(vm->stringClass, "!=(_)", string_bangeq);
PRIMITIVE(vm->stringClass, "+(_)", string_plus);
PRIMITIVE(vm->stringClass, "[_]", string_subscript);
PRIMITIVE(vm->stringClass, "byteAt_(_)", string_byteAt);
Expand Down

0 comments on commit d896dc9

Please sign in to comment.