meta method __newindex for reassignment...

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

meta method __newindex for reassignment...

Brendan Dowling-2
Hi,

I'd like to make a system for catching errors in a somewhat large Lua
project (~14,000 lines of Lua).  Specifically, I'd like to catch
reassignments of globals and entries in certain tables during the
initialization phase.  However, the __newindex meta method does not
seem to get called for reassignments, only new assignments.  This is
probably a pretty simple hack, but I didn't see it in a search of the
archives or a google search.



Thanks,

Brendan Dowling
Embedded Systems Engineer
Harman International

Reply | Threaded
Open this post in threaded view
|

Re: meta method __newindex for reassignment...

Duncan Cross
Take a look at the __usedindex patch: http://lua-users.org/wiki/LuaPowerPatches

On 5/15/07, Brendan Dowling <[hidden email]> wrote:
Hi,

I'd like to make a system for catching errors in a somewhat large Lua
project (~14,000 lines of Lua).  Specifically, I'd like to catch
reassignments of globals and entries in certain tables during the
initialization phase.  However, the __newindex meta method does not
seem to get called for reassignments, only new assignments.  This is
probably a pretty simple hack, but I didn't see it in a search of the
archives or a google search.



Thanks,

Brendan Dowling
Embedded Systems Engineer
Harman International


Reply | Threaded
Open this post in threaded view
|

Re: meta method __newindex for reassignment...

Gergo Szakal
In reply to this post by Brendan Dowling-2
On Mon, 14 May 2007 17:11:01 -0700
"Brendan Dowling" <[hidden email]> wrote:

> Hi,
> 
> I'd like to make a system for catching errors in a somewhat large Lua
> project (~14,000 lines of Lua).  Specifically, I'd like to catch
> reassignments of globals and entries in certain tables during the
> initialization phase.  However, the __newindex meta method does not
> seem to get called for reassignments, only new assignments.  This is
> probably a pretty simple hack, but I didn't see it in a search of the
> archives or a google search.

The Lua PIL provides information on this. You need to create a proxy table in which you can monitor the assignments and make the actual assignments on the real table.

http://www.lua.org/pil/13.4.4.html

Hope this helps.


Reply | Threaded
Open this post in threaded view
|

Re: meta method __newindex for reassignment...

Brendan Dowling-2
In reply to this post by Duncan Cross
That's perfect.  Thanks.  I like this solution better than the proxy idea.



On 5/14/07, Duncan Cross <[hidden email]> wrote:
Take a look at the __usedindex patch: http://lua-users.org/wiki/LuaPowerPatches

On 5/15/07, Brendan Dowling <[hidden email]> wrote:
> Hi,
>
> I'd like to make a system for catching errors in a somewhat large Lua
> project (~14,000 lines of Lua).  Specifically, I'd like to catch
> reassignments of globals and entries in certain tables during the
> initialization phase.  However, the __newindex meta method does not
> seem to get called for reassignments, only new assignments.  This is
> probably a pretty simple hack, but I didn't see it in a search of the
> archives or a google search.
>
>
>
> Thanks,
>
> Brendan Dowling
> Embedded Systems Engineer
> Harman International
>