diff src/eval.c @ 34472:5c1a025192ed v9.1.0148

patch 9.1.0148: Vim9: can't call internal methods with objects Commit: https://github.com/vim/vim/commit/d3eae7bc116297f70220f21ded436ed0a88066d8 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Sun Mar 3 16:26:58 2024 +0100 patch 9.1.0148: Vim9: can't call internal methods with objects Problem: Vim9: can't call internal methods with objects Solution: Add support for empty(), len() and string() function calls for objects (Yegappan Lakshmanan) closes: #14129 Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Sun, 03 Mar 2024 16:45:06 +0100
parents 6df143135376
children 64edf95a833a
line wrap: on
line diff
--- a/src/eval.c
+++ b/src/eval.c
@@ -6318,36 +6318,9 @@ echo_string_core(
 	    break;
 
 	case VAR_OBJECT:
-	    {
-		garray_T ga;
-		ga_init2(&ga, 1, 50);
-		ga_concat(&ga, (char_u *)"object of ");
-		object_T *obj = tv->vval.v_object;
-		class_T *cl = obj == NULL ? NULL : obj->obj_class;
-		ga_concat(&ga, cl == NULL ? (char_u *)"[unknown]"
-							     : cl->class_name);
-		if (cl != NULL)
-		{
-		    ga_concat(&ga, (char_u *)" {");
-		    for (int i = 0; i < cl->class_obj_member_count; ++i)
-		    {
-			if (i > 0)
-			    ga_concat(&ga, (char_u *)", ");
-			ocmember_T *m = &cl->class_obj_members[i];
-			ga_concat(&ga, m->ocm_name);
-			ga_concat(&ga, (char_u *)": ");
-			char_u *tf = NULL;
-			ga_concat(&ga, echo_string_core(
-					       (typval_T *)(obj + 1) + i,
-					       &tf, numbuf, copyID, echo_style,
-					       restore_copyID, composite_val));
-			vim_free(tf);
-		    }
-		    ga_concat(&ga, (char_u *)"}");
-		}
-
-		*tofree = r = ga.ga_data;
-	    }
+	    *tofree = r = object_string(tv->vval.v_object, numbuf, copyID,
+					echo_style, restore_copyID,
+					composite_val);
 	    break;
 
 	case VAR_FLOAT: