Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Improved SOURCE function

From: larry::ecotope::com at: 5-May-2001 15:28

Hi all, I got tired of the SOURCE function not working for items inside objects, so I wrote an improved version SRC which will do so. When the argument is not a path, it simply calls SOURCE. I stole the hard part of the code from Doc Kimbel's most excellent extended help function which is also an object browser. Doc may be interested in adding a refinement (like help/s arg) which would cause it to display the source for items in objects. Meanwhile you can use my function. If you like it, just invoke the script below in your user.r script. Here are some examples:
>> src rebol/view/vid/track
track: func [blk][if verbose [print blk]]
>> src rebol/view/vid/verbose
verbose: false
>> src ctx-viewtop/dbug
dbug: func [msg [block! any-string!] /local dbg][ if not dbg: user-prefs/debug [exit] msg: head insert remold msg "desktop " either file? dbg [write/append dbg msg] [print msg] ]
>> src cosine
cosine: native [ "Returns the trigonometric cosine in degrees." value [number!] /radians "Value is specified in radians." ]
Enjoy -Larry ---------------------------code below--------------------- REBOL [ Title: "Extended Source" Author: "Larry Palmiter" File: %src.r Date: 5-May-2001 Version: 0.1.0 Purpose: {Extends the SOURCE function to work when the argument is a path into an object } Comments: {I stole the hard part of the code from Doc Kimbel's wonderful extended help.r Thanks Nenad ! } ] src: func ['word /local value in-obj][ if not equal? type? :word path! [ source :word exit ] value: to-lit-path :word in-obj: repend copy [get in] [ copy/part value (length? value) - 1 word: to-lit-word last value ] if error? try [value: do in-obj][ print "Error: this is not a valid path !" exit ] prin join word ": " either any [native? :value op? :value action? :value][ print ["native" mold third :value] ][ print mold :value ] ]