This is a lightweight container class combining an SCM method call with a particular instance into a C++ callable. --- lily/callback.cc | 1 + lily/include/callback.hh | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+)
diff --git a/lily/callback.cc b/lily/callback.cc index fac40a0..baab7b0 100644 --- a/lily/callback.cc +++ b/lily/callback.cc @@ -22,3 +22,4 @@ const char * const Callback_wrapper::type_p_name_ = 0; const char * const Callback2_wrapper::type_p_name_ = 0; const char * const Callback0_wrapper::type_p_name_ = 0; +const char * const Method_instance::type_p_name_ = 0; diff --git a/lily/include/callback.hh b/lily/include/callback.hh index 7151d04..963f4eb 100644 --- a/lily/include/callback.hh +++ b/lily/include/callback.hh @@ -146,4 +146,45 @@ public: } }; +// The following will usually be used unsmobbified, relying on its +// constituents being protected independently. + +class Method_instance : public Simple_smob<Method_instance> +{ + SCM method_, instance_; +public: + static const char * const type_p_name_; // = 0 + LY_DECLARE_SMOB_PROC (&Method_instance::call, 0, 0, 1) + SCM call (SCM rest) + { + return scm_apply_1 (method_, instance_, rest); + } + + Method_instance (SCM method, SCM instance) + : method_ (method), instance_ (instance) + { } + Method_instance (SCM method, Smob_core *instance) + : method_ (method), instance_ (instance->self_scm ()) + { } + SCM method () const { return method_; } + SCM instance () const { return instance_; } + SCM operator () () const + { + return scm_call_1 (method_, instance_); + } + SCM operator () (SCM arg) const + { + return scm_call_2 (method_, instance_, arg); + } + SCM operator () (SCM arg1, SCM arg2) const + { + return scm_call_3 (method_, instance_, arg1, arg2); + } + SCM mark_smob () const + { + scm_gc_mark (method_); + return instance_; + } +}; + #endif -- 2.7.4 _______________________________________________ lilypond-devel mailing list lilypond-devel@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-devel