forked from Distributive-Network/PythonMonkey
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyTypeFactory.hh
More file actions
49 lines (39 loc) · 1.81 KB
/
pyTypeFactory.hh
File metadata and controls
49 lines (39 loc) · 1.81 KB
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
/**
* @file pyTypeFactory.hh
* @author Caleb Aikens (caleb@distributive.network) & Giovanni Tedesco (giovanni@distributive.network)
* @brief Function for wrapping arbitrary PyObjects into the appropriate PyType class, and coercing JS types to python types
* @version 0.1
* @date 2022-08-08
*
* @copyright Copyright (c) 2022
*
*/
#ifndef PythonMonkey_PyTypeFactory_
#define PythonMonkey_PyTypeFactory_
#include "PyType.hh"
#include <jsapi.h>
#include <Python.h>
/** @brief Function that takes an arbitrary PyObject* and returns a corresponding PyType* object
@author Caleb Aikens
@date August 2022
@param object - Pointer to the PyObject who's type and value we wish to encapsulate
*/
PyType *pyTypeFactory(PyObject *object);
/**
* @brief Function that takes a JS::Value and returns a corresponding PyType* object, doing shared memory management when necessary
*
* @param cx - Pointer to the javascript context of the JS::Value
* @param thisObj - Pointer to the JS `this` object for the value's scope
* @param rval - Pointer to the JS::Value who's type and value we wish to encapsulate
* @return PyType* - Pointer to a PyType object corresponding to the JS::Value
*/
PyType *pyTypeFactory(JSContext *cx, JS::Rooted<JSObject *> *thisObj, JS::Rooted<JS::Value> *rval);
/**
* @brief Helper function for pyTypeFactory to create FuncTypes through PyCFunction_New
*
* @param JSFuncAddress - Pointer to a PyLongObject containing the memory address of JS::Value containing the JSFunction*
* @param args - Pointer to a PyTupleObject containing the arguments to the python function
* @return PyObject* - The result of the JSFunction called with args coerced to JS types, coerced back to a PyObject type, or NULL if coercion wasn't possible
*/
static PyObject *callJSFunc(PyObject *JSFuncAddress, PyObject *args);
#endif