lua-users home
lua-l archive

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


Hi, list!

I apologize for being lazy, but can someone please summarize for me,
how environment sandboxing is to be done in 5.2? (I assume that
nothing is changed for CPU and memory sandboxing.)

In my code I heavily rely on the following pattern (pseudocode):

-- users_code.lua

foo()
bar()
baz = true
return 42

-- system_code.lua

local do_in_environment = function(chunk, env)
  arguments(
      "function", chunk,
      "table", env
    )

  setfenv(chunk, env)

  return xpcall(chunk, debug.traceback)
end

local env = -- Whitelist
{
  foo = foo;
  bar = bar;
}

local ok, result = assert(
    do_in_environment(
        assert(loadfile("users_code.lua")),
        env
      )
  )

print(result, env.baz)

Thanks,
Alexander.