Re: minisphere 1.1.6
Reply #528 –
The thing I really love about
RequireScript is that, besides providing built-in protection against multiple inclusion, it can also be used to enforce load order in complex libraries. In miniRT, for instance, the very bottom of miniRT.js has this block:
// now that everything is in order, we can pull in all the miniRT
// component scripts.
RequireSystemScript('mini/miniBGM.js');
RequireSystemScript('mini/miniConsole.js');
RequireSystemScript('mini/miniLink.js');
RequireSystemScript('mini/miniPact.js');
RequireSystemScript('mini/miniScenes.js');
RequireSystemScript('mini/miniThreads.js');
The components are listed in alphabetical order, however miniThreads actually has to be initialized first, because everything else in the runtime depends on it. And it indeed
does get initialized first because the individual component scripts also have a RequireScript for it, and therefore it gets its initializer registered with the runtime before any other component. This kind of thing I found is very difficult to do with modules because of the focus on encapsulation.
Nonetheless, this was a trivial addition I could have done ages ago (it's built into Duktape, and even if not it could be polyfilled easily using RawFiles and
eval), and implementing it now puts me in a very good position to start work on some form of Pegasus support.