lua-users home
lua-l archive

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


On 13/01/2010, at 3:48 AM, Dravonk wrote:

> It would be
>  file = assert (io.open (path))
>  source = file:read ("*all")
>  file:close ()
>  func = loadin (env, source, "@"..path)

This proposed solution assumes you want io.open to be available. If I want to replicate:

func = loadfile(path)
setfenv(func, env)
func()

... but have sandboxed out io.open, is there another solution? The reason for sandboxing out io.open is, for one thing, you can read arbitrary user files on disk (eg. files with passwords in them), and for another, you can open files for output. However loadfile cannot write to disk, and is restricted to reading files that have Lua code in them.

Doing this doesn't work:

in env do
  func = loadfile(path)
  func()
end 



- Nick