lua-users home
lua-l archive

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


Hi,

> > When you clone a namespace, the implementation still refers to the
> > original namespace. If you make changes to the cloned namespace (such as
> > changing a constant, or providing a new implementation for one of its
> > functions), the library's implementation will not see the changes.
> >
> > Anyone has an obvious solution for this problem?
> 	I don't think this is a problem...
> 	We have a similar situation in CGILua 5.0 with some launchers
> that persist with the server process (Apache module or FastCGI).  These
> launchers have to run one script per request in the same Lua state.
> Therefore we have to protect the global environment from one execution
> to another.  The solution was to create a Virtual Environment which
> inherits the globals from the original but kept any change inside it.
> After the script execution, it is thrown away.
> 	There is no "cloning", but inheritance.  The changes you pointed
> out will be restricted to the environment where they were made.

Let me give a better example (I am sorry to use LuaSocket all the time,
but for some reason it keeps comming to my head :o)). The http module
has a few constants on it. One is the default proxy, another is the
default user agent. The constants are inside the namespace (where else?).
For instance

    local http = require("http")
    http.PROXY = "http://locahost:3128"; -- make all requests use the proxy
    print(http.get("http://www.cs.princeton.edu/~diego";))
    print(http.get("http://www.tecgraf.puc-rio.br/~diego";))

What I am saying is that if you do

    http2 = clone(http)
    http2.PROXY = "whatever"

the implementation will still see the first value of PROXY, unless the
"clone" function is magic. I believe this is a problem, or is it?

[]s,
Diego.