[IronPython] OnVarChanged

John Mancine john at emergentlifetech.com
Tue Jun 20 11:04:30 PDT 2006


Thanks for the info. 

I think I have found what I was looking for now. Basically, this is the
earliest breakpoint that I hit after returning from the [Lightweight
Function] on the call stack after engine.Execute("a=1") is called.

IronPython.Runtime.ModuleScope.SetLocal(SymbolId symbol, object value)

Sure looks promising at least. The symbol is 'a' and the value is '1'. 

I also found a IronPython.Runtime.Operations.Ups.MakeClass() call which
should be helpful for hooking into class declarations. 

> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-
> bounces at lists.ironpython.com] On Behalf Of Michael Foord
> Sent: Tuesday, June 20, 2006 11:59 AM
> To: Discussion of IronPython
> Subject: Re: [IronPython] OnVarChanged
> 
> John Mancine wrote:
> > I realize this is likely woefully naïve but I thought I'd ask anyhow.
> >
> > I have a very specific case in my project where I would really like to
> know
> > when a variable inside IronPython changes. Basically when I do this:
> >
> > pythonEngine.Execute("a = 3"); // Or something more complex that ends up
> > changing global var 'a'
> >
> > I am looking for a way to be notified when 'a' has been assigned to a
> new
> > value. This seems to be pretty simple for the Set/GetGlobal() calls but
> what
> > about code that is inside of the Execute() block? Where could I look at
> > adding some code myself such that I can add these hooks? I have dug
> through
> > some of the code to find a place to add a hook but I couldn't seem to
> find
> > anything clear cut.
> >
> > Again, I realize this is pretty simplistic and also painfully slow for
> any
> > moderate scripting but I have a very specific case where I would like
> some
> > widgets in C# to respond to when a variable has changed. (The
> watchwindow in
> > visual studio would be a good parallel of what I'm needing to do -- ie.
> show
> > a new value has been set for a particular value you are watching).
> >
> >
> Hello John,
> 
> I may be off beam here (I'm no C# expert and know little about the
> IronPython internals) but it sounds like what you want to do is a bit at
> conflict with the way Python works.
> 
> Python doesn't have variables by value as such, it has names and objects.
> 
> In your example, 'a' isn't an object, it's a name bound to an object.
> 
> When you do :
> 
> a = 1
> a = 2
> 
> it's not that the value of a changes, instead the name is rebound to a
> different object. Tracking changes to a mutable object is one thing, but
> tracking name binding is a different thing altogether.
> 
> Perhaps you could replace the ``__dict__`` attribute of a module (where
> names are stored) with a custom 'dictionary-like' object, that calls a
> callback when assignments are made ? A better approach would be to use a
> value on an object (instead of a local variable), and you can get that
> object to perform a callback when changes are made.
> 
> All the best,
> 
> Fuzzyman
> http://www.voidspace.org.uk/python/index.shtml
> 
> > Thanks!
> > John
> >
> > _______________________________________________
> > users mailing list
> > users at lists.ironpython.com
> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> >
> >
> 
> _______________________________________________
> users mailing list
> users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the users mailing list