[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Access a member from within the table def
- From: Renato Maia <maia@...>
- Date: Fri, 14 May 2010 02:19:18 -0300
On Thu, May 13, 2010 at 2:35 PM, Brian Weed <brianw@imaginengine.com> wrote:
> Is there a way to do this:
>
> t = {
> foo = function() end,
> bar = some_global_function(foo),
> }
No. Some alternatives are:
t = {}
t.foo = function() end
t.bar = some_global_function(t.foo)
or
local function newtab(f)
local t = setmetatable({}, {__index=_G})
setfenv(f, t)()
return setmetatable(t, nil)
end
t = newtab(function()
foo = function() end
bar = some_global_function(foo)
end)
--
Renato Maia
Computer Scientist
Tecgraf/PUC-Rio
__________________________
http://www.inf.puc-rio.br/~maia/