Re: libseed-list Hooking into the imports system



Yes, that was a bit too much magic ;)

Committed
Regards
Alan

 --- On 30/Jun/2010, Jonatan Liljedahl wrote: 
> Alan Knowles wrote:
> ...
> > For the toString stuff, I guess that's needed only for this patch.
> 
> No, I think it should go in even without my 
> missing-module-handler-patch. Look at this:
> 
> lijon kymatix:~/Coding/seed$ ls -l mydir/
> total 12
> -rw-r--r-- 1 lijon lijon 59 2010-06-18 10:03 bar.js
> -rw-r--r-- 1 lijon lijon 79 2010-06-18 10:03 foo.js
> -rw-r--r-- 1 lijon lijon 43 2010-06-30 13:52 toString.js
> lijon kymatix:~/Coding/seed$ seed
>  > d = imports.mydir
> Oops, where did this come from?
> 
>  >^C
> lijon kymatix:~/Coding/seed$ cat mydir/toString.js
> print("Oops, where did this come from?");
> 
> /Jonatan
> 
> > 
> >  --- On 30/Jun/2010, Jonatan Liljedahl wrote: 
> >> Here is a small patch that adds a feature that I'd be very happy to see.
> >> It allows one to hook into the imports system by defining a handler for
> >> when a module was not found. Example:
> >>
> >>    imports.__notFoundHandler__ = function(name, dir) {
> >>      print("making "+name);
> >>      return {foo:123}
> >>    }
> >>    f = imports.foobar;
> >>    print(f.foo);
> >>
> >> running above file prints:
> >>
> >>    making foobar
> >>    123
> >>
> >> This can be used to integrate all sorts of cool stuff with the imports
> >> object. For example, the handler can iterate over imports.searchPath to
> >> find n+".html" and return an object representation of the DOM tree, or
> >> parsing a custom language (hmmmm ;)), or perhaps even connect to an
> >> online database of modules.. x = imports.seedgems.foo; -> updates foo
> >> from an online repository, etc...
> >>
> >> Currently it only passes the first path from seed_importer_search_dirs() 
> >> as the second arg, at least this works for the case when the search is 
> >> done inside a single directory, but I guess it would be better to just 
> >> send the whole path GSList by converting it to a JS array. One could 
> >> still work around it on the script side by merging the dir arg with 
> >> imports.searchPath if dir != searchPath[0].
> >>
> >> BTW, this patch also adds the toString and toValue hack to 
> >> seed_importer_dir_get_property() so it doesn't call the handler saying 
> >> that "toString" module wasn't found, etc..
> >>
> >> /Jonatan
> > 
> > _______________________________________________
> > libseed-list mailing list
> > libseed-list gnome org
> > http://mail.gnome.org/mailman/listinfo/libseed-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]