lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A more automated LY_DEFINE?


From: Jean Abou Samra
Subject: A more automated LY_DEFINE?
Date: Fri, 2 Sep 2022 10:42:15 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.0

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

[Prev in Thread] Current Thread [Next in Thread]