mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-18 13:49:59 +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 pop(Fiber* fiber);
|
||||||
static Value primitive_metaclass_new(Value receiver);
|
static Value primitive_metaclass_new(Value receiver);
|
||||||
static Value primitive_num_abs(Value receiver);
|
static Value primitive_num_abs(Value receiver);
|
||||||
|
static Value primitive_string_count(Value receiver);
|
||||||
|
|
||||||
VM* newVM()
|
VM* newVM()
|
||||||
{
|
{
|
||||||
@ -62,6 +63,9 @@ VM* newVM()
|
|||||||
vm->numClass = makeClass();
|
vm->numClass = makeClass();
|
||||||
PRIMITIVE(num, abs);
|
PRIMITIVE(num, abs);
|
||||||
|
|
||||||
|
vm->stringClass = makeClass();
|
||||||
|
PRIMITIVE(string, count);
|
||||||
|
|
||||||
return vm;
|
return vm;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -449,3 +453,11 @@ Value primitive_num_abs(Value receiver)
|
|||||||
|
|
||||||
return (Value)makeNum(value);
|
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