wdte icon indicating copy to clipboard operation
wdte copied to clipboard

std: allow user to specify importable modules

Open DeedleFake opened this issue 7 years ago • 0 comments

The module registration system was designed to work like the image package's decoder registration. Unfortunately, there's a large difference that I didn't take into account: Importing a package that registers a new module changes the behavior of every WDTE script parsed. This means that any kind of import of any package that calls std.Register() can break things. For example, if std/arrays imported std/stream in order to use NextFunc or something, suddenly stream becomes importable from WDTE.

To get around this, the currently globally-exposed std.Import should be replaced with a function, func Import(modules ...string) wdte.Importer, which returns a wdte.Importer that only allows the user to import the modules specified.

On top of this, it probably makes sense to remove std/all. Instead, std can pre-register all of the std/** modules, while those modules then don't have to import std at all. The downside to this is that all of those packages will be included in every Go package, but that's probably fine. The standard library's not particularly huge.

DeedleFake avatar Nov 28 '18 20:11 DeedleFake