lua-users home
lua-l archive

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


The Manual says that:
function f () body end
is translated to:
f=function() body end,

However, this code doesn't seem to work:
-----------------------------------------------------------------
do
  local cdoc
  local docs
  local function newindex(G,k,v)
    docs[k]=cdoc
    rawset(G,k,v)
    setmetatable(_G,nil)
  end
  function adddoc(s)
    cdoc=s
    setmetatable(_G,{__newindex=newindex})
  end
end
adddoc[[-----------------------
-- Some function doc
-- that has info in it
--Blah foo bar baz
----------------------------------]]
function Foo(arg1)
  doStuff()
end

----------------------------------------------------------------

Apparently function definitions like that bypass the __newindex
metamethod in the globals table. Why is this not stated?