mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-06 01:50:38 +00:00
Improve ResourceId repr/str handling, and add an int() handling
This commit is contained in:
@@ -71,11 +71,44 @@ CONTAINER_TYPEMAPS(rdctype::array)
|
||||
|
||||
// add __str__ functions
|
||||
%feature("python:tp_str") ResourceId "resid_str";
|
||||
%feature("python:tp_repr") ResourceId "resid_str";
|
||||
%feature("python:nb_int") ResourceId "resid_int";
|
||||
|
||||
%wrapper %{
|
||||
static PyObject *resid_str(PyObject *resid)
|
||||
{
|
||||
return PyUnicode_FromFormat("<ResourceId %S>", PyObject_GetAttrString(resid, "id"));
|
||||
void *resptr = NULL;
|
||||
unsigned long long *id = NULL;
|
||||
int res = SWIG_ConvertPtr(resid, &resptr, SWIGTYPE_p_ResourceId, 0);
|
||||
if (!SWIG_IsOK(res)) {
|
||||
SWIG_exception_fail(SWIG_ArgError(res), "in method 'ResourceId.str', ResourceId is not correct type");
|
||||
}
|
||||
|
||||
// cast as unsigned long long
|
||||
id = (unsigned long long *)resptr;
|
||||
static_assert(sizeof(unsigned long long) == sizeof(ResourceId), "Wrong size");
|
||||
|
||||
return PyUnicode_FromFormat("<ResourceId %llu>", *id);
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static PyObject *resid_int(PyObject *resid)
|
||||
{
|
||||
void *resptr = NULL;
|
||||
unsigned long long *id = NULL;
|
||||
int res = SWIG_ConvertPtr(resid, &resptr, SWIGTYPE_p_ResourceId, 0);
|
||||
if (!SWIG_IsOK(res)) {
|
||||
SWIG_exception_fail(SWIG_ArgError(res), "in method 'ResourceId.str', ResourceId is not correct type");
|
||||
}
|
||||
|
||||
// cast as unsigned long long
|
||||
id = (unsigned long long *)resptr;
|
||||
static_assert(sizeof(unsigned long long) == sizeof(ResourceId), "Wrong size");
|
||||
|
||||
return PyLong_FromUnsignedLongLong(*id);
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
%}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user