Christian wrote:
> I have the following use case with OpenGL:
> 
> My colours are stored in 4-element tuples and should be passed to a 
> OpenGL function by function unpacking
> 
> color = (0, 0, 0, 1)
> glColor4f(*color)
> 
> But this doesn't work with Cython. I get the following error:
> 
> 
> Error converting Pyrex file to C:
> ------------------------------------------------------------
> ...
> 
> def set_color():
>    color = (0, 0, 0, 1)
>    glColor4f(*color)
>            ^
> ------------------------------------------------------------
> 
> gltest.pyx:16:13: Keyword arguments not allowed in cdef functions.

Admittedly, the error message is misleading here. This is a feature that is
not supported.

The problem is that Cython cannot know at compile time that you pass the
right number of arguments to the function and that they have the right type
etc. So it would need to generate the corresponding tuple unpacking and
type conversion code, store the values in a series of temporary variables,
and then call the C function with them.

Without having looked into this any deeper, I think this can be supported
fairly easily using a parse tree transformation that simply injects the
unpacking step and types the temporary variables according to the C
function signature.

But it isn't currently supported.

Stefan

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to