Re: Registries

Daniel Wallin <[email protected]>
Newsgroups gmane.comp.lib.boost.langbinding
Message-ID <5.1.0.14.0.20030716175347.03b48b98__17661.2433665015$1059273089@student.umu.se>
At 17:32 2003-07-16, David Abrahams wrote:
>Daniel Wallin <[email protected]> writes:
>
> > At 15:38 2003-07-15, David Abrahams wrote:
> >>Daniel Wallin <[email protected]> writes:
> >>
> >>I'm not really sure it amounts to much.  The additional complication
> >>should go into the *registration* process instead of the lookup
> >>process, to make sure that lookup stays fast.
> >
> > Right... How would these scopes be specified by the user?
> > What constitutes a scope?
>
>I don't think the user would specify scopes explicitly, except to
>import from them.  They'd follow the nested structure of modules
>precisely, and the user would use module names to refer to them.

Could you explain more how the modules would nest, and how
would the scoping "just work"? How does a module know it's
parent?

> > Ok, there are two use cases:
> >
> >    Build you module as a shared lib and expose some function
> >    that binds all your C++ code to the lua state. There are
> >    some fairly standardized symbol names that are used for this
> >    (luaLM_version, luaLM_import).
>
>So this function goes into lua's global namespace and is called
>explicitly by the user to load the module?  It sounds a bit like the
>module init function used by python.

Well, there are different ways of handling this.. Lua has a built in function
that loads a function from a shared library. Used like this:

   local init = loadlib("mymodule.dll", "init_mymodule")
   init()

there's at least one extension that allows:

   loadmodule("mymodule.dll")

which I guess is almost equivalent to:

   function loadmodule(name)
     local init = loadlib(name, "luaLM_import")
     init()
   end

>Does the shared lib get opened with dlopen, thus ensuring link symbol
>isolation from other modules?

Yes, at least that's what I concluded after investigating the source to some
of the loaders.

> >    Bind your module directly to the interpreter by modifying the lua
> >    state:
> >
> >      lua_pushstring(L, "my_fun");
> >      lua_pushcclosure(L, &my_fun, 0);
>
>How does the code which does the binding get invoked?

Either by doing it in a function that's exposed from a shared lib, or by just
invoking it. :)

   int main()
   {
     lua_State* L = lua_open();
     lua_pushstring(L, "my_fun");
     lua_pushcclosure(L, &my_fun, 0);
     ..
   }

---
Daniel Wallin



-------------------------------------------------------
This SF.net email is sponsored by: VM Ware
With VMware you can run multiple operating systems on a single machine.
WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the
same time. Free trial click here: http://www.vmware.com/wl/offer/345/0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.