lua-users home
lua-l archive

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


Appologies for the "stream of thoughs", which is unsuitable for
mailing lists, but I want to share this idea too:

if Lua implemented a getfenv() function, you could actually manipulate
the scopes at will.

inject could then be defined as:

function inject(table,p)
      local scope = getfenv(2) --
      for _, v in ipairs( properties ) do
               scope[v] = var[v]
       end
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



2010/2/6 Pierre-Yves Gérardy <pygy79@gmail.com>:
> The new "in" syntax could be implemented as follows, BTW
>
> inside(table_,function()
>       a = 1
>       b=2
> end)
>
> function inside(table, f)
> setfenv(f,table)
> f()
> end
>