lua-users home
lua-l archive

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


>From lua-l@tecgraf.puc-rio.br  Thu Jun 15 06:42:11 2000
>From: "Maciej Maczynski" <macmac@xdsnet.de>

>I'd like to have some way to list recently created Lua globals.

Use the "setglobal" tag method for tag(nil) and save the names in a table.
Something like this (untested):

do
 local G={n=0}
 function set_checkpoint()
  settagmethod(tag(nil),"setglobal", function (n,v) tinsert(%G,n) end)
 end
 function print_new_globals()
  foreachi(%G,print)
 end
end

Note that the names of the new globals are stored and listed in the order
the variables are created. If you do not need this, the code below is simpler:

do
 local G={}
 function set_checkpoint()
  settagmethod(tag(nil),"setglobal", function (n,v) %G[n]=1 end)
 end
 function print_new_globals()
  foreach(%G,print)
 end
end

--lhf