Rebol Programming/dump-obj
Appearance
USAGE:
[edit | edit source]DUMP-OBJ obj /match pat
DESCRIPTION:
[edit | edit source]Returns a block of information about an object.
DUMP-OBJ is a function value.
ARGUMENTS
[edit | edit source]- obj -- (Type: object)
REFINEMENTS
[edit | edit source]- /match -- Include only those that match a string or datatype
- pat -- (Type: any)
SOURCE CODE
[edit | edit source]dump-obj: func [ "Returns a block of information about an object." obj [object!] /match "Include only those that match a string or datatype" pat /local clip-str form-val form-pad words vals str wild ][ clip-str: func [str] [ trim/lines str if (length? str) > 50 [str: append copy/part str 50 "..."] str ] form-val: func [val] [ if any-block? :val [return reform ["length:" length? val]] if image? :val [return reform ["size:" val/size]] if any-function? :val [ val: third :val if block? val/1 [val: next val] return clip-str either string? val/1 [copy val/1] [mold val] ] if object? :val [val: next first val] clip-str mold :val ] form-pad: func [val size] [ val: form val insert/dup tail val #" " size - length? val val ] words: first obj vals: next second obj obj: copy [] wild: all [string? pat find pat "*"] foreach word next words [ type: type?/word pick vals 1 str: form word if any [ not match all [ not unset? pick vals 1 either string? :pat [ either wild [ tail? any [find/any/match str pat pat] ] [ find str pat ] ] [ all [ datatype? get :pat type = :pat ] ] ] ] [ str: form-pad word 15 append str #" " append str form-pad type 10 - ((length? str) - 15) append obj reform [ " " str if type <> 'unset! [form-val pick vals 1] newline ] ] vals: next vals ] obj ]