-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExModule.cpp
67 lines (49 loc) · 1.69 KB
/
ExModule.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#define X_PY_VERSION 37
#include "PythonCore.h"
#include "Callable.h"
#include "ModuleBuilder.h"
#include "Object.h"
#include "./Utils.h"
#include <iostream>
using namespace xpo::python;
static PyObject* m_test(PyObject* self, PyObject* args) {
PyObject_Print(PyUnicode_FromString("Hello, MuOnline!"), stdout, 0);
return args;
}
static PyObject* say_hello(PyObject* self, PyObject* args, PyObject* kwargs) {
PyObject* callback;
if (!PyArg_ParseTuple(args, "O", &callback))
{
return NULL;
}
Callable callable{ callback };
callable(kwargs);
Py_RETURN_NONE;
}
static Object something(Module self, Tuple args) {
Tuple inner = Tuple(Tuple(args[0].ptr())[0].ptr());
TypedTuple<int, int, float> typed(inner);
auto [x, y, z] = typed.unpack();
std::cout << args.size() << x << ' ' << y << ' ' << z << std::endl;
return Object::none();
}
static Object something2(Module self, TypedTuple<int, int, float> args) {
auto [x, y, z] = args;
std::cout << args.size() << x << '|' << y << '|' << z << std::endl;
return Object::none();
}
static Object something3(Module self, int x, int y, float z) {
std::cout << x << '<' << y << '<' << z << std::endl;
return Object::none();
}
ModuleBuilder muonline{ "muonline" };
//typedef Object(*Ft)(Module, int, int, float);
//typedef Function2<Ft> Ft2;
PyMODINIT_FUNC PyInit_muonline() {
muonline.add_method("test1", m_test);
muonline.add_method("test2", say_hello);
muonline.add_method<something>("something");
muonline.add_method<PackedVarArgsFunctionObject(something2)>("something2");
muonline.add_method<something3>("something3");
return PyModule_Create(&muonline.module_definition());
}