lua-users home
lua-l archive

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

----- Original Message -----
From: steve donovan
Date: 2/19/2010 12:36 AM
On Thu, Feb 18, 2010 at 11:48 PM, Geoff Leyland
<>  wrote:
local env = {}
local f = assert (loadfile ("config.lua"))
setfenv (f, env) ()

... which lets you load a configuration file into a table, will no longer work under Lua 5.2.
I do exactly this too.  It'd be a shame if 5.2 broke it.
Do remember that loadin can also be passed a code string (like
loadstring) but then I guess you still have to have

Although surely this is not the kind of thing you would do in a sandbox?
Another way I use this pattern (which is all the time) is for merging multiple levels of config files:


Config = {
    -- Stuff


Config = {
    -- Stuff


local env = {}
local chunk = loadfile("UserConfig.lua")
setfenv(chunk, env)()

-- Merge env.Config into Config.

How do we do this efficiently under Lua 5.2?