-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathpython_interface.c
71 lines (58 loc) · 1.8 KB
/
python_interface.c
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
@file python_interface.c
@brief The main entry point for the code. All the magic starts here.
@author Rodrigo Luger ([rodluger](https://github.com/rodluger/))
@date May 14 2021
*/
#ifdef VPLANET_PYTHON_INTERFACE
#include "vplanet.h"
#define PY_SSIZE_T_CLEAN
#include <Python.h>
// Get the code version, passed in as a macro
#ifndef VPLANET_VERSION
#define VPLANET_VERSION_STRING "0.0.0"
#else
#ifdef VPLANET_ON_WINDOWS
// Silly Windows needs some extra love
#define STRINGIFY(X) #X
#define VPLANET_VERSION_STRING STRINGIFY(VPLANET_VERSION)
#else
#define VPLANET_VERSION_STRING VPLANET_VERSION
#endif
#endif
int main_impl(int, const char *(*)[9]);
static PyObject *vplanet_core_version(PyObject *self, PyObject *args) {
const char *version = VPLANET_VERSION_STRING;
PyObject *pVersion = PyBytes_FromString(version);
Py_INCREF(pVersion);
return pVersion;
}
static PyObject *vplanet_core_run(PyObject *self, PyObject *args) {
// Get the options (built-in max of 9)
int argc = PyTuple_GET_SIZE(args);
const char *argv[9];
if (!PyArg_ParseTuple(args, "|sssssssss", &argv[0], &argv[1], &argv[2],
&argv[3], &argv[4], &argv[5], &argv[6], &argv[7],
&argv[8])) {
return NULL;
}
// Run vplanet
main_impl(argc, &argv);
// Return None
Py_INCREF(Py_None);
return Py_None;
}
static PyMethodDef VplanetCoreMethods[] = {
{"run", vplanet_core_run, METH_VARARGS, NULL},
{"version", vplanet_core_version, METH_VARARGS, NULL},
{NULL, NULL, 0, NULL}};
static struct PyModuleDef vplanet_core_module = {
PyModuleDef_HEAD_INIT, "vplanet_core", NULL, -1, VplanetCoreMethods};
PyMODINIT_FUNC PyInit_vplanet_core(void) {
PyObject *m = PyModule_Create(&vplanet_core_module);
if (m == NULL) {
return NULL;
}
return m;
}
#endif