From 17eda4dedb0d70c5a82edf77e9b3aaa1af5bfb19 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sat, 12 Oct 2024 19:32:20 +0200 Subject: Initial support for Python --- python/nissy_module.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 python/nissy_module.c (limited to 'python') diff --git a/python/nissy_module.c b/python/nissy_module.c new file mode 100644 index 0000000..b627300 --- /dev/null +++ b/python/nissy_module.c @@ -0,0 +1,34 @@ +#define PY_SSIZE_T_CLEAN +#include + +#include "../src/nissy.h" + +/* TODO from here */ + +static PyObject *compose(PyObject *self, PyObject *args) { + const char *cube, *permutation; + char result[NISSY_SIZE_B32]; + + if (!PyArg_ParseTuple(args, "ss", &cube, &permutation)) + return NULL; + + nissy_compose(cube, permutation, result); + return PyUnicode_FromString(result); +} + +static PyMethodDef NissyMethods[] = { + { "compose", compose, METH_VARARGS, "Compose two cubes." }, + { NULL, NULL, 0, NULL } +}; + +static struct PyModuleDef nissy_python_module = { + PyModuleDef_HEAD_INIT, + "nissy", + NULL, + -1, + NissyMethods +}; + +PyMODINIT_FUNC PyInit_nissy_python_module(void) { + return PyModule_Create(&nissy_python_module); +} -- cgit v1.3