lua-users home
lua-l archive

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


On 24/10/2012, at 9:19 AM, Konstantinos Asimakis <inshame@gmail.com> wrote:

> Conversely, why does this not raise an error:
> 
> io.close=nil
> h=io.open("something","r")
> h:close()
> 
> I thought that I could remove methods from tables by setting them to nil in order to create sandboxed versions of the basic tables. But being able to call close as a method on the file handle pretty much ruins that. Then how do you properly sandbox io functions? Do I have to wrap io.open to store internally (in an upvalue) the actual handles and return some other object to the user that lacks the original :read :close etc methods?

$ lua -e "local f = io.open('test', 'w'); getmetatable(f).close = nil; f:close()"
lua: (command line):1: attempt to call method 'close' (a nil value)
stack traceback:
	(command line):1: in main chunk
	[C]: ?