-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreenmodule.cpp
48 lines (40 loc) · 1.13 KB
/
screenmodule.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// this might be mac-specific
#include <Python/Python.h>
// #include "screen.h"
// this seems like a hack - is this really how python wants me to do this?
#include "screen.cpp"
static Screen *sc;
static PyObject *screenInit(PyObject *self, PyObject *args) {
if (!PyArg_ParseTuple(args, "")) {
return NULL;
}
sc = (Screen *) malloc(sizeof(Screen));
*sc = Screen();
Py_RETURN_NONE;
}
static PyObject *screenDrawToBuffer(PyObject *self, PyObject *args) {
if (!PyArg_ParseTuple(args, "")) {
return NULL;
}
sc->drawToBuffer();
Py_RETURN_NONE;
}
static PyObject *screenDraw(PyObject *self, PyObject *args) {
if (!PyArg_ParseTuple(args, "")) {
return NULL;
}
int out = sc->draw();
return Py_BuildValue("i", out);
Py_RETURN_NONE;
}
static PyMethodDef ScreenMethods[] = {
{"init", screenInit, METH_VARARGS, "Create a screen object."},
{"drawToBuffer", screenDrawToBuffer, METH_VARARGS, "Render state to internal buffer."},
{"draw", screenDraw, METH_VARARGS, "Draw internal buffer to screen."},
{NULL, NULL, 0, NULL}
};
PyMODINIT_FUNC
initcscreen(void)
{
(void) Py_InitModule("cscreen", ScreenMethods);
}