-
|
I am new to this library and I'd like to create bindings for a struct like this: struct FrameTaskParams {
double position_cost = 1.0;
double orientation_cost = 1.0;
double task_gain = 1.0;
double lm_damping = 0.0;
};Claude proposed to create the bindings like this: nanobind::class_<FrameTaskParams>(m, "FrameTaskParams")
.def(nanobind::init<>())
.def(
"__init__",
[](FrameTaskParams* self, double position_cost, double orientation_cost, double task_gain,
double lm_damping) {
new (self) FrameTaskParams{position_cost, orientation_cost, task_gain, lm_damping};
},
"position_cost"_a = 1.0, "orientation_cost"_a = 1.0, "task_gain"_a = 1.0,
"lm_damping"_a = 0.0, "Constructor with custom parameters.")Is there a better (maybe without a lambda) way to create bindings for the struct while keeping the option for to do Aggregate initialization for the struct in C++? Thanks in advance for your help! |
Beta Was this translation helpful? Give feedback.
Answered by
wjakob
Feb 3, 2026
Replies: 1 comment 1 reply
-
|
Use |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
sjahr
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use
.def(nb::init<type1, type2, ..>()). That will use aggregate initialization automatically.