resonance 1.0.1
Loading...
Searching...
No Matches
module.h
Go to the documentation of this file.
1#pragma once
2
3#include "script/cxx/config.h"
4#include "script/cxx/dict.h"
5#include "script/cxx/object.h"
6
7class HxStr;
8
9namespace Py {
10
31class Module : public Object {
32public:
47 explicit Module(const HxStr &name) : Object() {
48 set(PyImport_ImportModule(
49 const_cast<char *>(name.mStr != nullptr ? name.mStr : g_szEmptyString)));
50 validate();
51 }
52
61 Dict getDict() const {
62 return Dict(PyModule_GetDict(mPtr));
63 }
64};
65
66} // namespace Py
Heap-allocated NUL-terminated string.
Definition hxstr.h:41
char * mStr
Text buffer.
Definition hxstr.h:464
Handle on a Python dictionary.
Definition dict.h:30
Module(const HxStr &name)
Import a module by name and wrap it.
Definition module.h:47
Dict getDict() const
Produce a handle on the module's namespace.
Definition module.h:61
void set(PyObject *pyob)
Replace the reference with a borrowed one and add a count of its own.
Definition object.h:215
Object(PyObject *pyob=Py_None)
Take a borrowed reference and add a count of its own.
Definition object.h:52
void validate()
Enforce this type's accepts() test on the stored reference.
Definition object.h:237
PyObject * mPtr
Wrapped reference, null only between release() and the next assignment.
Definition object.h:191
Configuration header of the PyCXX binding layer.
const char * g_szEmptyString
Text an empty HxStr points at, and the substitute for a null buffer.
C++ wrappers for the embedded Python interpreter's objects, types, and extension modules.
Definition attributeerror.h:7