Login
dll.s2 at [af1b0ff74b]
Login

File s2/require.d/plugins/dll.s2 artifact de8c8fc205 part of check-in af1b0ff74b


/**
   Uses s2.loadModule() to load s2 loadable modules. Usage:

   dll!moduleName?options...

   The return value: if moduleProperty option is NOT provided
   and the module produces only a single property (as most
   do), that property's value is returned, otherwise the whole
   "namespace object" passed to the module init routine is
   returned. That possibly has potential backfire cases, but
   none affecting any current modules.

   Options:

   ACHTUNG: Be aware that require() caching will hold the
   first result from this plugin's load() call (and
   generically _not_ caching DLL results is dangergous), so
   any options provided to this function via a require() call
   here are only honored on the first call. On subsequent
   calls require() will use the cached result.

   entryPoint=string: if set, it is used as the second param
   to s2.loadModule().

   moduleProperty=string: if set, the result of the call is
   the given property from the DLL module. The majority of
   DLLs install only a single property, and this function will
   return only that property in such cases (as described
   above).
*/
const mod = {
    cacheIt: true /* _not_ caching DLL-loaded resources is a
                     Reall Bad Idea, as the DLL can change
                     between invocations, leaving us with
                     different binary signatures. Also,
                     functions injected via DLLs need access
                     to the C side, which disappears if a DLL
                     is closed. */,
    prefix: ('string' === typename (var dllTmp = s2.getenv('S2_MODULE_PATH')))
        ? dllTmp.split(dllTmp.indexOf(';') >= 0 ? ';' : ':')
    : ['.'],
    suffix: ('string' === typename (dllTmp = s2.getenv('S2_MODULE_EXTENSIONS')))
        ? dllTmp.split(dllTmp.indexOf(';') >= 0 ? ';' : ':')
    : ['.so','.dll'],
    load: function(name,opt){
        var rc;
        affirm name && 'string' === typename name;
        rc = (opt && opt.entryPoint)
            ? s2.loadModule(name, opt.entryPoint, {})
            : s2.loadModule(name, {});
        affirm rc;
        if(opt && opt.hasOwnProperty('moduleProperty')){
            rc = rc[opt.moduleProperty];
        }else if(var keys=rc.propertyKeys();
                 1===keys.length()){
            rc = rc[keys.0];
        }
        return rc;
    }
};

mod.prefix.push( requireS2.home + s2.io.dirSeparator + 'dll'  );

return mod;