sanya84
@sanya84
Фанатик Python 3

Как это void glutDisplayFunc(void (*functionName)(void)); привести к типу Python 3 через 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>
  • Вопрос задан
  • 75 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
24 апр. 2024, в 22:11
2000 руб./за проект
24 апр. 2024, в 22:00
500 руб./в час
24 апр. 2024, в 21:49
10000 руб./за проект