Thanks a lot, I think I'm getting closer to it but can't get this to
work with dynamic-require. So I've switched to sandbox, and still the
imported modules from the current module are just not available in the
sandboxed module:

(require racket/gui/base
         racket/sandbox
         racket/runtime-path
         gregor
         (prefix-in internat: "../core/internat.rkt")
         (prefix-in pref: "../core/prefs.rkt")
         (prefix-in db: "../core/dbaccess.rkt")
         (prefix-in dates: "../core/dates.rkt")
         (prefix-in metafonts: "../core/metafonts.rkt")
         (prefix-in threaded: "../core/threaded.rkt")
         (prefix-in console: "console.rkt"))
       ;   "../notetaker/notetaker-main.rkt")

(define-runtime-path notetaker
  "../notetaker/notetaker-main.rkt")

(define-namespace-anchor a)

(define notes-panel%
  (call-with-trusted-sandbox-configuration
   (lambda ()
     (let* ([ns (namespace-anchor->namespace a)]
            [path-index (variable-reference->module-path-index
(#%variable-reference))]
            [dbaccess (module-path-index-join  "../core/dbaccess.rkt"
path-index)])
 
       (parameterize ([sandbox-namespace-specs (list (lambda () ns)
(module-path-index-resolve dbaccess))])
         (let ([evaluator (make-module-evaluator notetaker)])
           (evaluator 'notes-panel%)))))))

When I run it, it says that some binding from dbaccess.rkt is not
available in the sandboxed module. But I'm adding it in the
sandbox-namespace-specs list. With dynamic-require I got essentially
the same result with manually attaching it and then calling
namespace-require.

Why does this not work?

Best,

Erich



On Thu, 9 Feb 2017 06:00:19 -0700
Matthew Flatt <mfl...@cs.utah.edu> wrote:

> A variable reference produced by `(#%variable-reference)` can serve as
> the starting point for reflective operations on modules. Specifically,
> use
> 
>  (variable-reference->module-path-index (#%variable-reference))
> 
> to get a reference to the enclosing module, and use
> `module-path-index-join` on that value and "../core/internat.rkt"
> to get a reference to the "../core/internat.rkt" module.
> 
> At Thu, 9 Feb 2017 12:25:35 +0000, Erich Rast wrote:
> > Out of general curiosity I'm still trying to figure out how a
> > dynamic plugin system would work. So now I'd like to
> > namespace-attach-module for all modules that the current module
> > imports (and their submodules), and then namespace-require them.
> > 
> > The problem is that I don't know how to attach modules required by
> > relative paths and with prefix-in, because I don't know their
> > symbolic name (if they have one). What I'm attempting is this:
> > 
> > (require racket/gui/base
> >          racket/runtime-path
> >          gregor
> >          (prefix-in internat: "../core/internat.rkt"))
> > 
> > (define-runtime-path notetaker
> >          "../notetaker/notetaker-main.rkt")
> > 
> > 
> > (define notes-panel%
> >   (let ([ns (make-base-empty-namespace)])
> >     (namespace-attach-module (current-namespace)
> >                              'racket/gui/base
> >                              ns)
> >     (namespace-attach-module (current-namespace)
> >                              'gregor
> >                              ns)
> >     (namespace-attach-module (current-namespace)
> >                              "../core/internat.rkt"
> >                              ns)
> >     (parameterize ([current-namespace ns])
> >       (namespace-require 'racket/gui/base)
> >       (namespace-require 'gregor)
> >       (namespace-require  "../core/internat.rkt")
> >       (dynamic-require notetaker 'notes-panel%))))
> > 
> > where the respective require for internat is left out in
> > notetaker-main.rkt, since the dynamically required module needs the
> > instance of the module *from the calling module's namespace*, not a
> > separate copy. But this fails for "internat.rkt" - and it also will
> > not create the right module path in the compiled distribution
> > binary, it seems.
> > 
> > Is there an internal symbolic name for the module required with
> > prefix-in and relative path?
> > 
> > Best,
> > 
> > Erich
> > 
> > -- 
> > You received this message because you are subscribed to the Google
> > Groups "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it,
> > send an email to racket-users+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.  

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to