On Jan 10, 12:58 pm, Christophe Grand <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] a écrit :
>
>
>
> > Hi,
>
> > I am starting to get pretty serious about using Rhino as a general
> > purpose server-side language, and one of the main issues that I still
> > need to solve is package/namespace management. I strongly suspect that
> > someone has developed a solution to this already, but if not then I
> > will be trying to figure something out. The characteristics that will
> > be needed are as follows:
>
> > 1. Code in a given file needs to enter the global namespace only when
> > explicitly specified (presumably it needs to occupy its own scope?)
> > 2. A package/namespace needs to be able to export functions that can
> > be imported and invoked from other packages
> > 3. Ideally, the namespaces would be organized hierarchically so that
> > one could import foo.bar.* and receive the entire contents of the
> > package and any packages deeper in the hierarchy
> > 4. Some mapping to actual files on the disk is of course called for,
> > as well as a way to load them into the process
>
> > In short, I need equivalent functionality to the Perl/Python/Ruby
> > family of dynamic languages (as these are the languages I hope to
> > replace with Rhino). I have some idea of how I would go about writing
> > such a facility, but given that this need has likely been felt before
> > I thought I would solicit any existing solution (or at least advice
> > about how to do it).
>
> > Has anybody seen or written anything like this? It seems like it might
> > make a lot of sense for Rhino to offer functionality like this out of
> > the box.
>
> The package system I'm using addresses your points #1, #2 and #4.
>
> Package definition:
> Package("package-name", function(pkg) {
> // package code goes here
> pkg.exported_property = 3.14;
> });
>
> Package import:
> const [pkg1, pkg2] = Package.get("pkg1-name", "pkg2-name");
>
> Package also has a pluggable loading strategy (which is rather dependent
> on my current project) and I also maintain a dependency graph for
> dynamic reloading.
>
> If that meets your requirements I can try and extract it (at least the
> part covering your points #1 and #2.)
>
> Christophe
What you describe is absolutely what I'm looking for. If you can
provide code that would be wonderful, and if not I would certainly
appreciate any description you could give. This sounds like such a
common thing to need, I'm surprised that a standard for this has not
emerged yet. If you are willing to share your code, perhaps it could
become the basis for a library?
Many Thanks,
Ben Reesman
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino