mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 06:08:41 +01:00
"count" method on strings.
This commit is contained in:
12
src/vm.c
12
src/vm.c
@ -38,6 +38,7 @@ static void push(Fiber* fiber, Value value);
|
||||
static Value pop(Fiber* fiber);
|
||||
static Value primitive_metaclass_new(Value receiver);
|
||||
static Value primitive_num_abs(Value receiver);
|
||||
static Value primitive_string_count(Value receiver);
|
||||
|
||||
VM* newVM()
|
||||
{
|
||||
@ -62,6 +63,9 @@ VM* newVM()
|
||||
vm->numClass = makeClass();
|
||||
PRIMITIVE(num, abs);
|
||||
|
||||
vm->stringClass = makeClass();
|
||||
PRIMITIVE(string, count);
|
||||
|
||||
return vm;
|
||||
}
|
||||
|
||||
@ -449,3 +453,11 @@ Value primitive_num_abs(Value receiver)
|
||||
|
||||
return (Value)makeNum(value);
|
||||
}
|
||||
|
||||
|
||||
Value primitive_string_count(Value receiver)
|
||||
{
|
||||
double count = strlen(((ObjString*)receiver)->value);
|
||||
|
||||
return (Value)makeNum(count);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user