lua-users home
lua-l archive

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


I am trying to convert a program from lua 5.1 to lua 5.2. The program keeps
data in tables and allows the user to write a lua script which makes changes
to the data. In order to restrict the possibilities of the user I did set an
environment to the imported lua script so that the script is sandboxed.
Additionally the program can also automatically generate these scripts.

In pseudo code this looks like (I did not use assert in the example to make
it easier to read):

function execute_script(code,path)
  local script
  if code then -- code contains automatically generated code
    script = loadstring(code)
  else
    script = loadfile(path)
    setfenv(script,env) -- where env is a table containing the environment
  end
  script()
end

Can you suggest a good way to transfer this code to lua 5.2? It seems that
loadstring is not available anymore and may be replaced by load or loadin? 

thank you very much,
Michael