Rebol 编程/dump-obj
外观
< Rebol 编程
DUMP-OBJ obj /match pat
返回关于对象的块信息。
DUMP-OBJ 是一个函数值。
- obj -- (类型:对象)
- /match -- 只包括那些匹配字符串或数据类型的对象
- pat -- (类型:任何)
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 ]