@@ -145,7 +145,17 @@ bool __MCForeignValueIsEqualTo(__MCForeignValue *self, __MCForeignValue *other_s
145145
146146bool __MCForeignValueCopyDescription (__MCForeignValue *self, MCStringRef& r_description)
147147{
148- return false ;
148+ MCTypeInfoRef t_resolved_typeinfo;
149+ t_resolved_typeinfo = __MCTypeInfoResolve (self->typeinfo );
150+
151+ bool (*t_describe_func)(void *, MCStringRef &);
152+ t_describe_func = t_resolved_typeinfo->foreign .descriptor .describe ;
153+
154+ if (NULL != t_describe_func)
155+ return t_describe_func (MCForeignValueGetContentsPtr (self),
156+ r_description);
157+ else
158+ return MCStringFormat (r_description, " <foreign: %p>" , self);
149159}
150160
151161// //////////////////////////////////////////////////////////////////////////////
@@ -312,6 +322,53 @@ static bool __double_export(MCValueRef value, bool release, void *contents)
312322 return true ;
313323}
314324
325+ static bool
326+ __bool_describe (void *contents,
327+ MCStringRef & r_string)
328+ {
329+ return MCStringCopy (MCSTR (*((bool *) contents) ? " <foreign true>" : " <foreign false>" ), r_string);
330+ }
331+
332+ static bool
333+ __int_describe (void *contents,
334+ MCStringRef & r_string)
335+ {
336+ return MCStringFormat (r_string, " <foreign integer %i>" ,
337+ *((integer_t *) contents));
338+ }
339+
340+ static bool
341+ __uint_describe (void *contents,
342+ MCStringRef & r_string)
343+ {
344+ return MCStringFormat (r_string, " <foreign unsigned integer %u>" ,
345+ *((uinteger_t *) contents));
346+ }
347+
348+ static bool
349+ __float_describe (void *contents,
350+ MCStringRef & r_string)
351+ {
352+ return MCStringFormat (r_string, " <foreign float %g>" ,
353+ (double ) *((float *) contents));
354+ }
355+
356+ static bool
357+ __double_describe (void *contents,
358+ MCStringRef & r_string)
359+ {
360+ return MCStringFormat (r_string, " <foreign double %g>" ,
361+ *((double *) contents));
362+ }
363+
364+ static bool
365+ __pointer_describe (void *contents,
366+ MCStringRef & r_string)
367+ {
368+ return MCStringFormat (r_string, " <foreign pointer %p>" ,
369+ *((void **) contents));
370+ }
371+
315372static bool __build_typeinfo (const char *p_name, MCForeignTypeDescriptor *p_desc, MCTypeInfoRef& r_typeinfo)
316373{
317374 MCAutoStringRef t_name_string;
@@ -355,6 +412,7 @@ bool __MCForeignValueInitialize(void)
355412 d . hash = __bool_hash;
356413 d . doimport = __bool_import;
357414 d . doexport = __bool_export;
415+ d . describe = __bool_describe;
358416 if (!__build_typeinfo (" __builtin__.bool" , &d, kMCBoolTypeInfo ))
359417 return false ;
360418
@@ -373,6 +431,7 @@ bool __MCForeignValueInitialize(void)
373431 d . hash = __int_hash;
374432 d . doimport = __int_import;
375433 d . doexport = __int_export;
434+ d . describe = __int_describe;
376435 if (!__build_typeinfo (" __builtin__.int" , &d, kMCIntTypeInfo ))
377436 return false ;
378437
@@ -391,6 +450,7 @@ bool __MCForeignValueInitialize(void)
391450 d . hash = __int_hash;
392451 d . doimport = __uint_import;
393452 d . doexport = __uint_export;
453+ d . describe = __uint_describe;
394454 if (!__build_typeinfo (" __builtin__.uint" , &d, kMCUIntTypeInfo ))
395455 return false ;
396456
@@ -409,6 +469,7 @@ bool __MCForeignValueInitialize(void)
409469 d . hash = __float_hash;
410470 d . doimport = __float_import;
411471 d . doexport = __float_export;
472+ d . describe = __float_describe;
412473 if (!__build_typeinfo (" __builtin__.float" , &d, kMCFloatTypeInfo ))
413474 return false ;
414475
@@ -427,6 +488,7 @@ bool __MCForeignValueInitialize(void)
427488 d . hash = __double_hash;
428489 d . doimport = __double_import;
429490 d . doexport = __double_export;
491+ d . describe = __double_describe;
430492 if (!__build_typeinfo (" __builtin__.double" , &d, kMCDoubleTypeInfo ))
431493 return false ;
432494
@@ -445,6 +507,7 @@ bool __MCForeignValueInitialize(void)
445507 d . hash = __pointer_hash;
446508 d . doimport = nil;
447509 d . doexport = nil;
510+ d . describe = __pointer_describe;
448511 if (!__build_typeinfo (" __builtin__.pointer" , &d, kMCPointerTypeInfo ))
449512 return false ;
450513
0 commit comments