lua-users home
lua-l archive

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



On 7 May 2011, at 05:21, Alexander Gladysh wrote:
I apologize for being lazy, but can someone please summarize for me,
how environment sandboxing is to be done in 5.2?

local env = { foo = foo; bar = bar }
local path = "users_code.lua"
local loader = assert(io.open(path)):lines()
local chunk = assert(loadin(env, loader, path))
local ok, result = assert(xpcall(chunk, debug.traceback))
print(result, env.baz)

This makes me wonder again if there is any way to load code from files using a custom environment without the need to put all the file's contents in strings (nor going to C and write yourself a 'loadfilein' sort of function).

--
Renato Maia
Computer Scientist
Tecgraf/PUC-Rio
__________________________
http://www.inf.puc-rio.br/~maia/