[Pyrex] How to access C variable of other class?
Gustavo Barbieri
barbieri at gmail.com
Wed Oct 6 03:35:24 CEST 2004
Hello,
I'm [trying to] writting a python wrapper for libvisual
(http://libvisual.sf.net/), but I have some problems:
1) Is this code all right?
--8<----------------------------------
def init( argv ):
"""Initialize libvisual.
Sets up a plugin registry, register the program name and such.
Parameters:
* argv: list of strings representing the argument
Returns: 0 on succes -1 on error.
"""
if not isinstance( argv, list ):
raise TypeError( "argument must be a list of strings!" )
# hold original values
cdef int aco
cdef char **avo
# hold to be passed values
cdef int ac
cdef char **av
aco = len( argv )
if aco == 0:
raise TypeError( "argument list must contain at least one argument!" )
# build an argument list
avo = <char **>calloc( aco, sizeof(char *) )
for i from 0 <= i < aco:
if not isinstance( argv[ i ], str ):
free( avo )
raise TypeError( "argument must be a list of strings!" )
txt = argv[ i ]
avo[ i ] = txt
av = avo
ac = aco
ret = visual_init( &ac, &av )
# rebuild argv from the modified av
del argv[ : ]
for i from 0 <= i < ac:
argv.append( av[ i ] )
free( avo )
return ret
-->8----------------------------------
2) libvisual is pure C, but have an OO concept, so I want to make it
OO in python migrating visual_video_*() to methods of the Video class.
My class is:
cdef class Video:
cdef VisVideo *video
The show stopper is:
visual_video_clone( VisVideo *dst, VisVideo *src )
Which I translated in:
cdef class Video:
def clone( self, src ):
visual_video_clone( self.video, src.video )
but I get the following error:
"Cannot convert Python object to 'VisVideo (*)'"
I already tried to have a method
getvideo(self): return self.video
and even played with cdef getvideo( instance ): return instance.video,
but none worked...
Could someone help me?
--
Gustavo Sverzut Barbieri
---------------------------------------
Computer Engineer 2001 - UNICAMP
GPSL - Grupo Pro Software Livre
Cell..: +55 (19) 9165 8010
Jabber: gsbarbieri at jabber.org
ICQ#: 17249123
GPG: 0xB640E1A2 @ wwwkeys.pgp.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libvisual.pyx
Type: application/octet-stream
Size: 10326 bytes
Desc: not available
Url : http://lists.copyleft.no/pipermail/pyrex/attachments/20041005/151f8178/libvisual.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: setup.py
Type: application/x-python
Size: 378 bytes
Desc: not available
Url : http://lists.copyleft.no/pipermail/pyrex/attachments/20041005/151f8178/setup.bin
More information about the Pyrex
mailing list