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

Discussion in 'Python' started by iwl, Dec 7, 2006.

  1. iwl

    iwl Guest

    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.
    iwl, Dec 7, 2006
    #1
    1. Advertising

  2. iwl

    Guest

    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
    , Dec 7, 2006
    #2
    1. Advertising

  3. iwl

    iwl Guest

    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
    iwl, Dec 7, 2006
    #3
  4. iwl

    Guest

    On 7 dic, 11:33, "iwl" <> 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
    , Dec 7, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wolfgang
    Replies:
    0
    Views:
    280
    Wolfgang
    Mar 17, 2005
  2. Colin Paul Gloster
    Replies:
    48
    Views:
    1,834
    Colin Paul Gloster
    Apr 10, 2007
  3. Krzysztof Kobus

    embedded python on mac - linking problem

    Krzysztof Kobus, Jan 5, 2010, in forum: Python
    Replies:
    1
    Views:
    252
    Diez B. Roggisch
    Jan 5, 2010
  4. Thomas Dodds

    Databind an embedded control in an embedded datagrid

    Thomas Dodds, Jul 26, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    381
    Thomas Dodds
    Jul 26, 2004
  5. Bojan Petrovic
    Replies:
    1
    Views:
    143
    Hidetoshi NAGAI
    Dec 3, 2005
Loading...

Share This Page