mirror of
https://github.com/lief-project/LIEF
synced 2026-06-08 15:30:44 +00:00
Switch the bindings to nanobind (and update the CI)
This commit is contained in:
@@ -17,54 +17,29 @@
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <nanobind/stl/string.h>
|
||||
|
||||
#include "LIEF/MachO/hash.hpp"
|
||||
#include "LIEF/MachO/DyldEnvironment.hpp"
|
||||
|
||||
#include "pyMachO.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace MachO {
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (DyldEnvironment::*)(void) const;
|
||||
|
||||
template<class T>
|
||||
using setter_t = void (DyldEnvironment::*)(T);
|
||||
#include "MachO/pyMachO.hpp"
|
||||
|
||||
namespace LIEF::MachO::py {
|
||||
|
||||
template<>
|
||||
void create<DyldEnvironment>(py::module& m) {
|
||||
void create<DyldEnvironment>(nb::module_& m) {
|
||||
|
||||
py::class_<DyldEnvironment, LoadCommand>(m, "DyldEnvironment",
|
||||
nb::class_<DyldEnvironment, LoadCommand>(m, "DyldEnvironment",
|
||||
R"delim(
|
||||
Class that represents a LC_DYLD_ENVIRONMENT which is
|
||||
used by the Mach-O linker/loader to initialize an environment variable
|
||||
)delim")
|
||||
)delim"_doc)
|
||||
|
||||
.def_property("value",
|
||||
static_cast<getter_t<const std::string&>>(&DyldEnvironment::value),
|
||||
static_cast<setter_t<const std::string&>>(&DyldEnvironment::value),
|
||||
"Environment variable as a string",
|
||||
py::return_value_policy::reference_internal)
|
||||
|
||||
.def("__eq__", &DyldEnvironment::operator==)
|
||||
.def("__ne__", &DyldEnvironment::operator!=)
|
||||
.def("__hash__",
|
||||
[] (const DyldEnvironment& env) {
|
||||
return Hash::hash(env);
|
||||
})
|
||||
|
||||
|
||||
.def("__str__",
|
||||
[] (const DyldEnvironment& env)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << env;
|
||||
return stream.str();
|
||||
});
|
||||
|
||||
}
|
||||
.def_prop_rw("value",
|
||||
nb::overload_cast<>(&DyldEnvironment::value, nb::const_),
|
||||
nb::overload_cast<const std::string&>(&DyldEnvironment::value),
|
||||
"Environment variable as a string"_doc,
|
||||
nb::rv_policy::reference_internal)
|
||||
|
||||
LIEF_DEFAULT_STR(DyldEnvironment);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user