Skip to content

Commit 761e354

Browse files
committed
libfoundation: Implement __MCHandlerCopyDescription().
Add a `describe()` callback to the `MCHandlerCallbacks` structure. If not provided, just describe as "<handler>".
1 parent 8f21db3 commit 761e354

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

libfoundation/include/foundation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,6 +2479,7 @@ struct MCHandlerCallbacks
24792479
size_t size;
24802480
void (*release)(void *context);
24812481
bool (*invoke)(void *context, MCValueRef *arguments, uindex_t argument_count, MCValueRef& r_value);
2482+
bool (*describe)(void *context, MCStringRef& r_desc);
24822483
};
24832484

24842485
MC_DLLEXPORT bool MCHandlerCreate(MCTypeInfoRef typeinfo, const MCHandlerCallbacks *callbacks, void *context, MCHandlerRef& r_handler);

libfoundation/src/foundation-handler.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ bool __MCHandlerIsEqualTo(__MCHandler *self, __MCHandler *other_self)
7474

7575
bool __MCHandlerCopyDescription(__MCHandler *self, MCStringRef& r_desc)
7676
{
77-
return false;
77+
if (NULL != self->callbacks->describe)
78+
return self->callbacks->describe(MCHandlerGetContext (self), r_desc);
79+
80+
/* Default implementation. */
81+
/* FIXME Should include information about arguments and return
82+
* values, extracted from the handler's typeinfo. */
83+
return MCStringCopy(MCSTR("<handler>"), r_desc);
7884
}
7985

8086
////////////////////////////////////////////////////////////////////////////////

libfoundation/src/foundation-string.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,6 @@ bool MCStringFormatV(MCStringRef& r_string, const char *p_format, va_list p_args
757757
/* UNCHECKED */ MCStringFormat(&t_string, t_value == kMCTrue ? "<true>" : "<false>");
758758
else if (MCValueGetTypeCode(t_value) == kMCValueTypeCodeNull)
759759
/* UNCHECKED */ MCStringFormat(&t_string, "<null>");
760-
else if (MCValueGetTypeCode(t_value) == kMCValueTypeCodeHandler)
761-
/* UNCHECKED */ MCStringFormat(&t_string, "<handler>");
762760
else
763761
/* UNCHECKED */ MCValueCopyDescription (t_value, &t_string);
764762

0 commit comments

Comments
 (0)