angerangel edited this page Jan 4, 2013 · 1 revision

USAGE

   LOAD source /header /all /type ftype /next

DESCRIPTION

Loads code or data from a file, URL, string, or binary.

LOAD is a function value.

ARGUMENTS

  • source -- Source or block of sources (file! url! string! binary! block!)

REFINEMENTS

  • /header -- Result includes REBOL header object (preempts /all)
  • /all -- Load all values (does not evaluate REBOL header)
  • /type -- Override default file-type; use NONE to always load as code
    • ftype -- E.g. text, markup, jpeg, unbound, etc. (word! none!)
  • /next -- Removed - use TRANSCODE instead

#SOURCE

load: make function! [  [
    {Loads code or data from a file, URL, string, or binary.}
    source [file! url! string! binary! block!] "Source or block of sources"
    /header {Result includes REBOL header object (preempts /all)}
    /all "Load all values (does not evaluate REBOL header)"
    /type {Override default file-type; use NONE to always load as code}
    ftype [word! none!] "E.g. text, markup, jpeg, unbound, etc."
    /next "Removed - use TRANSCODE instead"
    /local sftype data hdr
][
    assert/type [local none!]
    case/all [
        next [
            print "LOAD/next removed. Use TRANSCODE."
            cause-error 'script 'no-refine [load next]
        ]
        header [all: none]
        block? source [
            return map-each item source [apply :load [:item header all type ftype] ]
        ]
        any [file? source url? source] [
            sftype: file-type? source
            ftype: case [
                lib/all ['unbound = ftype 'extension = sftype] [sftype]
                type [ftype]
                'else [sftype]
            ]
            data: read-decode source ftype
        ]
        none? data [data: source]
        any [block? data not find [0 extension unbound] any [ftype 0] ] [
            return data
        ]
        not all [
            set [hdr: data:] either object? data [load-ext-module data] [load-header data]
            if word? hdr [cause-error 'syntax hdr source]
        ]
        not block? data [data: to block! data]
        header [insert data hdr]
        not any [
            'unbound = ftype
            'module = select hdr 'type
            find select hdr 'options 'unbound
        ] [data: intern data]
        not any [
            all
            header
            empty? data
            1 < length? data
        ] [data: first data]
    ]
    :data
] ]
Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.