lua-users home
lua-l archive

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


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/