Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Embedded python adding variables linking to C++-Variables / callbacks (http://www.velocityreviews.com/forums/t397116-embedded-python-adding-variables-linking-to-c-variables-callbacks.html)

iwl 12-07-2006 10:48 AM

Embedded python adding variables linking to C++-Variables / callbacks
 
Hello,

I would like to add Variables to my embedded python which represents
variables from my
C++-Programm.
I found C-Api-funcs for adding my C-Funcs to python but none to add
variables.
I would like some C-Function is called when the added Python-varible is
set (LValue) and
some other when it is read (RValue). Can I do this.
May be I have to do this in python and call the C-Funcs from a python
callback.

May be somebody can give short hints what to look for.


gagsl-py@yahoo.com.ar 12-07-2006 12:04 PM

Re: Embedded python adding variables linking to C++-Variables / callbacks
 
iwl ha escrito:

> I would like to add Variables to my embedded python which represents
> variables from my
> C++-Programm.
> I found C-Api-funcs for adding my C-Funcs to python but none to add
> variables.
> I would like some C-Function is called when the added Python-varible is
> set (LValue) and
> some other when it is read (RValue). Can I do this.
> May be I have to do this in python and call the C-Funcs from a python
> callback.


Write some C functions -callable from Python- which will be used to get
and set the variable value.
>From inside Python, declare a property with getter and setter which

will call your C functions.
This works fine for object attributes. If you want to trap references
to local or global "variables", I think you could provide customized
dictionaries for locals and globals, but I'm not sure if it works
really.

--
Gabriel Genellina


iwl 12-07-2006 02:33 PM

Re: Embedded python adding variables linking to C++-Variables / callbacks
 

gagsl-py@yahoo.com.ar schrieb:
>
> Write some C functions -callable from Python- which will be used to get
> and set the variable value.
> >From inside Python, declare a property with getter and setter which

> will call your C functions.
> This works fine for object attributes. If you want to trap references
> to local or global "variables", I think you could provide customized
> dictionaries for locals and globals, but I'm not sure if it works
> really.
>

Thank you I will try this.
What I found out up to now is to create a class inherited from an
fitting type
and overwrite the __setitem__ and __getitem__ method but haven't test
this
yet, something like that:

class test(int):
__setitem(self, value)__: C-Set-Func(value)
__getitem(self)__: return C-Get-Func()

x=test()
x= -> C-Set-Func called
y=x -> C-Get-Func called

something seems not yet correct


gagsl-py@yahoo.com.ar 12-07-2006 08:54 PM

Re: Embedded python adding variables linking to C++-Variables / callbacks
 
On 7 dic, 11:33, "iwl" <Ingo.W...@gmx.de> wrote:

> What I found out up to now is to create a class inherited from an
> fitting type
> and overwrite the __setitem__ and __getitem__ method but haven't test
> this
> yet, something like that:
>
> class test(int):
> __setitem(self, value)__: C-Set-Func(value)
> __getitem(self)__: return C-Get-Func()
>
> x=test()
> x= -> C-Set-Func called
> y=x -> C-Get-Func called


Python doesn't work that way: http://effbot.org/zone/python-objects.htm



All times are GMT. The time now is 08:26 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.