Import

angerangel edited this page Jan 4, 2013 · 1 revision
Clone this wiki locally

USAGE

   IMPORT module /version ver /check sum /no-share /no-lib /no-user

DESCRIPTION

Imports a module; locate, load, make, and setup its bindings.

IMPORT is a function value.

ARGUMENTS

  • module (word! file! url! string! binary! module! block!)

REFINEMENTS

  • /version
    • ver -- Module must be this version or greater (tuple!)
  • /check
    • sum -- Match checksum (must be set in header) (binary!)
  • /no-share -- Force module to use its own non-shared global namespace
  • /no-lib -- Don't export to the runtime library (lib)
  • /no-user -- Don't export to the user context

#SOURCE

import: make function! [  [
    {Imports a module; locate, load, make, and setup its bindings.}
    module [word! file! url! string! binary! module! block!]
    /version ver [tuple!] "Module must be this version or greater"
    /check sum [binary!] "Match checksum (must be set in header)"
    /no-share {Force module to use its own non-shared global namespace}
    /no-lib "Don't export to the runtime library (lib)"
    /no-user "Don't export to the user context"
    /local name mod file exports hdr
][
    if block? module [
        assert [not version not check]
        return apply :do-needs [module no-share no-lib no-user /block]
    ]
    set [name: mod:] apply :load-module [module version ver check sum no-share no-lib /import]
    case [
        mod none
        word? module [
            file: append to file! module system/options/default-suffix
            foreach path system/options/module-paths [
                if set [name: mod:] apply :load-module [
                    path/:file version ver check sum no-share no-lib /import /as module
                ] [break]
            ]
        ]
        any [file? module url? module] [
            cause-error 'access 'cannot-open reduce [module "not found or not valid"]
        ]
    ]
    unless mod [cause-error 'access 'cannot-open reduce [module "module not found"] ]
    case [
        no-user none
        not block? exports: select hdr: spec-of mod 'exports none
        empty? exports none
        any [no-lib find select hdr 'options 'private] [
            resolve/extend/only system/contexts/user mod exports
        ]
        not no-lib [resolve/only system/contexts/user lib exports]
    ]
    mod
] ]