10.13.1 Callback overview

This is a broad, shallow description of how C++ functions can call or be called by Scheme. For more depth, see Callback tutorial.

Calling Scheme functions from C++

For static dependencies, C++ wrappers around Guile’s C interface allow the syntax Module::function (/*args*/). This command lists imported Scheme modules and their C++ namespaces:

git grep -A2 '^namespace' lily/lily-imports.cc

Function (Variable) imports follow the Scm_module in each namespace block. Declarations are in lily/include/lily-imports.hh.

Defining Scheme-callable C++ functions

For a general function with Scheme name ly:fn:

LY_DEFINE (function, "ly:fn", //...

For a property accessor with Scheme name ly:fn that can be used alone or as the target of set!:

LY_DEFINE_WITH_SETTER (getter, "ly:fn", setter, //...

For a Grob callback function with Scheme name g::fn, any of:

MAKE_SCHEME_CALLBACK (structure, member_function, "g::fn", //...
MAKE_SCHEME_CALLBACK_WITH_OPTARGS (structure, member_function, "g::fn", //...
MAKE_DOCUMENTED_SCHEME_CALLBACK (structure, member_function, "g::fn", //...

For detail, see the definitions of the above macros in lily/include/lily-guile-macros.hh.


LilyPond Contributor’s Guide v2.27.1 (development-branch).