[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Lexical environments: follow-up
- From: Pierre-Yves Gérardy <pygy79@...>
- Date: Sat, 6 Feb 2010 14:00:06 +0100
Hi
since I subscribed to the Lua ML after the last post about the topic,
I can't reply to the proper thread.
I propose this pattern:
-- for one offs:
setenv(1, inject( {"Lurhman"}, Baz ) )
-- otherwise
local scope = {}
inject( {"insert", "remove"}, table, scope )
inject( {"sin", "cos"}, math, scope )
setenv(scope)
-- Inject:
function inject( properties, var, s )
local scope = s or {}
for _, v in ipairs( properties ) do
scope[v] = var[v]
end
return setmetatable( scope, {__index = _G} )
end
_______________________
Pierre-Yves Gérardy, MD
Headache Research Unit
University of Liege
Citadelle Hospital (University dept. of Neurology),
Boulevard du XIIe de Ligne, 1
B4000 Liège, Belgium
Phone : +32 (0) 4 225 71 41
Mobile : +32 (0) 472 543 727
Fax : +32 (0) 4 223 88 07
Department Secretary : Ms Groven : +32 (0) 4 225 63 91