Re: Registries [2]
David Abrahams <[email protected]>
| Newsgroups | gmane.comp.lib.boost.langbinding |
|---|---|
| Message-ID | <[email protected]> |
Daniel Wallin <[email protected]> writes: >> > Also, at least in lua. Modules could be loaded at any time, so there isn't >> > really a point where we can assume everything is loaded and import >> > converters. >> >>Can't you do something similar to the above? > > I don't think so. When I said "at any time" I didn't mean concurrently. > Consider (lua code): > > loadmodule "X" -- exposes f(std::vector<double>) > loadmodule "Y" -- exposes some convenience converters > -- lua -> C++ std::vector<double> > > We would really like for module X to be able to use the converters > introduced by module Y here, but module X is already initialized > when module Y's converters are created. The way I envisioned it: module X is loaded; loading_count = 1 module X's initialization function imports converters from module Y, which causes Y to be loaded and initialized loading_count = 2 Y registers its converters if Y imports converters from X, we notice that X is currently being initialized, and we push the request on a queue Y's initialization completes; loading_count = 1 X registers its converters X's initialization completes; loading_count = 0 Because loading_count = 0, we look at the import request queue and find the X->Y request. We satisfy that. >> >> >> > How are extensions to be registered in this central registry? In my >> >> >> > previous post I proposed that they should be registered with a >> >> >> > string literal identifier. >> >> >> > >> >> >> > register_extension("my_extension"); >> >> >> > >> >> >> > How does this fit in with pythons module system? (Note that we are >> >> >> > really registering the extension, and not modules). >> >> >> >> >> >>Every extension is a module (not nececssarily the other way around), >> >> >>so I see no reason not to register the extension by its module name >> >> > >> >> > I guess in python you can ask the interpreter state for the current >> >> > module name? >> >> >> >>Erm, I'm not sure you can. It is supplied as part of the module >> >>initialization function; in fact, it is stored in the module object as >> >>its __name__ attribute, so we can get it thence, assuming we can get >> >>to the module. >> > >> > Ok. >> > >> >> > In lua this isn't possible though, so we would need some user defined >> >> > identifier instead. >> >> >> >>You've gotta have the module or its name stored somewhere, dontcha? >> > >> > Other than in the .so filename? No. >> >>Why not just store it then? When you create it, stick a string in its >>__name__ attribute. > > I don't know what this means, create what? And what string? And how? > :) When you create the module, stick the name of the module in its name attribute, e.g. struct lua_module : lua_object { lua_module(char const* name) { ... this->attr("__name__") = name; ... } }; Also, take a look at the BOOST_PYTHON_MODULE macro. -- Dave Abrahams Boost Consulting www.boost-consulting.com ------------------------------------------------------- This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET. http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01