Skip to content
angerangel edited this page Mar 15, 2013 · 1 revision

USAGE

   DUMP-OBJ obj /match pat

DESCRIPTION

Returns a block of information about an object or port.

DUMP-OBJ is a function value.

ARGUMENTS

  • obj (object! port!)

REFINEMENTS

  • /match -- Include only those that match a string or datatype
    • pat

#SOURCE

dump-obj: make function! [  [
    {Returns a block of information about an object or port.}
    obj [object! port!]
    /match "Include only those that match a string or datatype" pat
    /local clip-str str form-val val form-pad out wild type
][
    clip-str: func [str] [
        trim/lines str
        if (length? str) > 45 [str: append copy/part str 45 "..."]
        str
    ]
    form-val: func [val] [
        if any-block? :val [return reform ["length:" length? val] ]
        if image? :val [return reform ["size:" val/size] ]
        if datatype? :val [return get in spec-of val 'title]
        if any-function? :val [
            return clip-str any [title-of :val mold spec-of :val]
        ]
        if object? :val [val: words-of val]
        if typeset? :val [val: to-block val]
        if port? :val [val: reduce [val/spec/title val/spec/ref] ]
        if gob? :val [return reform ["offset:" val/offset "size:" val/size] ]
        clip-str mold :val
    ]
    form-pad: func [val size] [
        val: form val
        insert/dup tail val #" " size - length? val
        val
    ]
    out: copy []
    wild: all [string? pat find pat "*"]
    foreach [word val] obj [
        type: type?/word :val
        str: either find [function! closure! native! action! op! object!] type [
            reform [word mold spec-of :val words-of :val]
        ] [
            form word
        ]
        if any [
            not match
            all [
                not unset? :val
                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 out reform [
                "  " str
                if type <> 'unset! [form-val :val]
                newline
            ]
        ]
    ]
    out
] ]
Clone this wiki locally