Last active
May 23, 2021 10:57
-
-
Save SirmaXX/70650a47ccee169efe1eee7708fe70ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <Python.h> | |
int addition (int a, int b) { | |
return a+b; | |
} | |
// sum of two number | |
static PyObject* DemoLib_addition(PyObject *self, PyObject *args) { | |
int a; | |
int b; | |
if (!PyArg_ParseTuple(args, "ii", &a, &b)) { | |
return NULL; | |
} | |
return Py_BuildValue("i", addition(a,b)); | |
} | |
// module's function table | |
static PyMethodDef demoMethods[] ={ | |
{"addition", DemoLib_addition, METH_VARARGS, "sum of two number"}, | |
{NULL, NULL, 0, NULL} | |
}; | |
static struct PyModuleDef demomodule = { | |
PyModuleDef_HEAD_INIT, | |
"demo", | |
NULL, | |
-1, | |
demoMethods | |
}; | |
PyMODINIT_FUNC | |
PyInit_demo(void) | |
{ | |
Py_Initialize(); | |
return PyModule_Create(&demomodule); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import demo | |
# kütüphane yükleyelim | |
a,b=int(input()),int(input()) | |
result=addition(a,b) | |
print("toplam ",result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from setuptools import Extension, setup | |
module = Extension("demo", | |
sources=[ | |
'demo.c' | |
]) | |
setup(name='demo', | |
version='1.0', | |
description='example demo package', | |
ext_modules=[module]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment