Hi,

Right now, the most common pattern for a LY_DEFINE is somewhat repetitive:

LY_DEFINE (ly_name, "ly:name",
           req, opt, var, (SCM arg1, SCM arg2, ...),
           R"(doc...)")
{
  LY_ASSERT_TYPE (is_scm<Cpp_type> (arg1), 1);
  Cpp_type arg1_cpp = from_scm<Cpp_type> (arg1);
  auto *const smob = LY_ASSERT_SMOB (Smob_type, arg2, 2);
  // process the arguments ...
  return to_scm (result);
}


We have this really all over the code base.

Does C++ provide tools for making this simpler? I'm thinking that something like

LY_DEFINE (ly_grob_relative_coordinate, ..., (Grob *g, Grob *refp, Axis a), ...)
{
  ...
  return ret;
}

would be equivalent to

LY_DEFINE (ly_grob_relative_coordinate, ..., (SCM g_scm, SCM refp_scm, SCM axis_scm), ...)
{
  auto *const g = LY_ASSERT_SMOB (Grob, g_scm, 1);
  auto *const refp = LY_ASSERT_SMOB (Grob, refp_scm, 2);
  LY_ASSERT_TYPE (is_scm<Axis>, axis_scm, 3);
  Axis a = from_scm<Axis> (axis_scm);
  ...
  return to_scm (ret);
}


If this is feasible, I might be willing to spend time on it in the future,
although not very soon.

If it is not feasible, being told it before I try could save me time. I'm
not yet very familiar with C++ templating techniques.

Thanks,
Jean


Reply via email to