Add class name to method __repr__

This commit is contained in:
K. Lange 2021-01-05 15:36:09 +09:00
parent ab158260f7
commit 181e378628
2 changed files with 5 additions and 3 deletions

View File

@ -29,7 +29,7 @@ Let's do some classes.
<type 'Test'>
yay: bax
bar
<method doAThing>
<method Test.doAThing>
yay: bar
This is a great teapot!
Subclass says: (I am a teapot)

6
vm.c
View File

@ -1857,9 +1857,11 @@ static KrkValue _bound_str(int argc, KrkValue argv[]) {
KrkValue s = _bound_get_name(argc, argv);
krk_push(s);
size_t len = AS_STRING(s)->length + sizeof("<method >");
const char * typeName = krk_typeName(AS_BOUND_METHOD(argv[0])->receiver);
size_t len = AS_STRING(s)->length + sizeof("<method >") + strlen(typeName) + 1;
char * tmp = malloc(len);
sprintf(tmp, "<method %s>", AS_CSTRING(s));
sprintf(tmp, "<method %s.%s>", typeName, AS_CSTRING(s));
s = OBJECT_VAL(krk_copyString(tmp,len-1));
free(tmp);
krk_pop();