lua-users home
lua-l archive

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

> I've came up with this:

> function sandbox(env, f, ...)
> 	local g = getfenv(f)
> 	setfenv(f, env)
> 	local retval = f(unpack(arg))
> 	setfenv(f, g)
> 	return retval
> end

While using this sandbox implementation I encounter a problem.

function xxx()
	SandBox['DATE'] = 1
	DATE = 1
	SandBox['Date'] = Date
	local outcome = sandbox(SandBox, f)
	return outcome

Function f, called by xxx, refers to global variable DATE.
The problem is that SandBox.DATEE is not used (and __index is not
called) when f is evaluated so I have to assign to global DATEE before
calling f. 

Why is this and how it could be cured? Is it because a DATEE become an
upvalue? Should I change DATEE references into getdate() fun. call to
prevent this?

Regards, max.