lua-users home
lua-l archive

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


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