lua-users home
lua-l archive

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


Thanks a lot!!!
Only after your post I realized that PIL has some code related. Difficult to deduce only with the manual.

victor
----- Original Message ----- From: "Dirk Laurie" <dirk.laurie@gmail.com>
To: "Lua mailing list" <lua-l@lists.lua.org>
Sent: Wednesday, August 14, 2013 1:47 PM
Subject: Re: source of declared variable


2013/8/14 Victor Bombi <sonoro@telefonica.net>:

If it's in the global namespace, you could write a __newindex metamethod
that keeps track of the line from which it is called.

Do you mean a metamethod for _G ?
I dont understand how to get the line, the methametod just receives (table,
key, value)

-- file xxx.lua

local getinfo=debug.getinfo

function newindex(t,key,val)
  local info=getinfo(2)
  print ("setting "..key.." from line "..info.currentline..
     " in file "..info.short_src)
  rawset(t,key,val)
end

setmetatable(_ENV,{__newindex=newindex})

function abc()
  trigger = true
end

abc()


$ lua xxx.lua
setting abc from line 12 in file xxx.lua
setting trigger from line 13 in file xxx.lua