A
A
Alexander2019-02-16 18:43:29
Python
Alexander, 2019-02-16 18:43:29

Like this void glutDisplayFunc(void (*functionName)(void)); cast to Python 3 type via Cython?

PYX FILE

cdef extern from "glut.h":
    void glutInitDisplayMode(int mode);
    void glutInitWindowPosition(int x, int y);
    void glutInitWindowSize(int width, int height);
    int glutCreateWindow(char *title);
    void glutDisplayFunc(void (*functionName)(void));

    void glutMainLoop();



def PythonGlutInitDisplayMode(mode):
    glutInitDisplayMode(mode)

def PythonGlutInitWindowPosition(x, y):
    glutInitWindowPosition(x, y)

def PythonGlutInitWindowSize(width, height):
    glutInitWindowSize(width, height)

def PythonGlutCreateWindow(title):
    return glutCreateWindow(title.encode('cp1251'))

def PythonGlutDisplayFunc(functionName):
    glutDisplayFunc(functionName)

def PythonGlutMainLoop():
    glutMainLoop()

error:
Microsoft Windows [Version 6.3.9600]
(c) Корпорация Майкрософт (Microsoft Corporation), 2013. Все права защищены.

C:\PyScripterProjects\PyGlut2>py setup.py build_ext --inplace
Compiling pyglut.pyx because it changed.
Cythonizing pyglut.pyx

Error compiling Cython file:
------------------------------------------------------------
...
cdef extern from "glut.h":
    void glutInitDisplayMode(int mode);
    void glutInitWindowPosition(int x, int y);
    void glutInitWindowSize(int width, int height);
    int glutCreateWindow(char *title);
    void glutDisplayFunc(void (*functionName)(void));
                                             ^
------------------------------------------------------------

pyglut.pyx:6:46: Use spam() rather than spam(void) to declare a function with no
 arguments.

Error compiling Cython file:
------------------------------------------------------------
...

def PythonGlutCreateWindow(title):
    return glutCreateWindow(title.encode('cp1251'))

def PythonGlutDisplayFunc(functionName):
    glutDisplayFunc(functionName)
                               ^
------------------------------------------------------------

pyglut.pyx:25:32: Cannot convert Python object to 'void (*)(void)'
Traceback (most recent call last):
  File "setup.py", line 8, in <module>
    language="c++",                      # generate and compile C++ code
  File "C:\Python36\lib\site-packages\Cython\Build\Dependencies.py", line 825, i
n cythonize
    cythonize_one(*args[1:])
  File "C:\Python36\lib\site-packages\Cython\Build\Dependencies.py", line 944, i
n cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: pyglut.pyx

C:\PyScripterProjects\PyGlut2>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question