lua-users home
lua-l archive

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


> Namespace cloning is a dirty solution, because the library that created
> the namespace is not aware of it. Sonner or later you will need to add
> a __clone() method. But then you might as well use a constructor ...

You didn't understand what I meant. If you load the module again, than
of course Rici's idea works. So does Roberto's idea, with a simple
modification to the implementation of "require". If we are not to allow
cloning, there is no problem.

My question is how important cloning is. It is cheaper to do some magic
with copy-on-write than to create a new namespace every time you need to
run a script in a sandbox. But is it worth it?

> The module chunk is executed outside the sandbox and can load other modules
> or access other globals. The constructor is executed inside the sandbox,
> but gets access to the outside through upvalues defined as locals for
> the module scope.
> Try to do this in a generic way without the constructor approach. :-)

I don't understand the difference. A chunk works just like any function,
just like a constructor. It *is* a function when you call loadfile.
What is the difference? Can't you setup your sandbox stuff before
calling the chunk?