lua-users home
lua-l archive

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

On 11/02/2010, at 1:19 PM, Peter Cawley wrote:

> If you're the one implementing the sandbox, then make available to the
> sandbox your own implementation of loadfile which allows for custom
> environments.

Thanks for the suggestion.

I want to point out to the Lua developers however that any solution involving the io library (as yours does) means that to do something simple like load a configuration file you now need to move from "core" Lua (loadfile and setfenv were in the base library) into incorporating the "io" library as well, something you may not want to do.

Here's an example of what I am talking about, using Lua to load up a program configuration, which might look like this:

width = 100
height = 50
players = 2
print = false

-- load configuration
local config = {}
local f = assert (loadfile ("config.lua"))
setfenv (f, config) ()

-- use it
print (config.width, config.height, config.print)

Now that simple usefulness seems to be gone.

If I may suggest, a new function like "loadfilein" which lets you specify an environment? Or modify loadfile to accept an environment as well as a file name.

- Nick