diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp index a3f9fc8..90495d8 100644 --- a/pykd/pymod.cpp +++ b/pykd/pymod.cpp @@ -773,6 +773,7 @@ BOOST_PYTHON_MODULE( pykd ) .def( "__str__", TypedVarAdapter::print ) .def("__len__", TypedVarAdapter::getElementCount ) .def("__getitem__", TypedVarAdapter::getElementByIndex ) + .def("__dir__", TypedVarAdapter::getElementsDir) //.def("__getitem__", &kdlib::TypedVar::getElementByIndexPtr ) ; diff --git a/pykd/pytypedvar.cpp b/pykd/pytypedvar.cpp index 0060436..ae4f67b 100644 --- a/pykd/pytypedvar.cpp +++ b/pykd/pytypedvar.cpp @@ -97,5 +97,31 @@ python::list TypedVarAdapter::getFields( kdlib::TypedVar& typedVar ) /////////////////////////////////////////////////////////////////////////////// +python::list TypedVarAdapter::getElementsDir(kdlib::TypedVar& typedVar) +{ + std::list lst; + + do { + + AutoRestorePyState pystate; + + for (size_t i = 0; i < typedVar.getElementCount(); ++i) + { + std::wstring name = typedVar.getElementName(i); + lst.push_back(name); + } + + } while (false); + + python::list pylst; + + for (std::list::const_iterator it = lst.begin(); it != lst.end(); ++it) + pylst.append(*it); + + return pylst; +} + +/////////////////////////////////////////////////////////////////////////////// + } // namesapce pykd diff --git a/pykd/pytypedvar.h b/pykd/pytypedvar.h index 046eeb2..b80dd1c 100644 --- a/pykd/pytypedvar.h +++ b/pykd/pytypedvar.h @@ -124,6 +124,7 @@ struct TypedVarAdapter { return typedVar.deref(); } + static python::list getElementsDir(kdlib::TypedVar& typedVar); }; } // end namespace pykd