lilypond-1.3.124
[lilypond.git] / lily / cxx-function-smob.cc
blob796e33470ac952da06e2eb2fe7cd773779b19f42
1 /*
2 grob-callback.cc -- implement Callback smob.
4 source file of the GNU LilyPond music typesetter
6 (c) 2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "cxx-function-smob.hh"
11 #include "ly-smobs.icc"
13 static long callback_tag;
15 static
16 SCM mark_smob (SCM)
18 return SCM_EOL;
21 static int
22 print_smob (SCM, SCM port, scm_print_state *)
24 scm_puts ("#<encapsulated C++ function>", port);
25 return 1;
28 static
29 scm_sizet free_smob (SCM)
31 return 0;
35 SCM
36 cxx_function_type_p (SCM x)
38 return (SCM_CELL_TYPE(x) == callback_tag) ? SCM_BOOL_T : SCM_BOOL_F;
41 void init_cxx_function_smobs()
43 callback_tag = scm_make_smob_type_mfpe ("callback", 0,
44 mark_smob, free_smob,
45 print_smob, 0);
47 scm_make_gsubr ("c++-function?", 1, 0, 0, (Scheme_function_unknown) cxx_function_type_p);
50 SCM
51 smobify_cxx_function (Cxx_function cb)
53 SCM z;
55 SCM_NEWCELL(z);
56 SCM_SETCDR (z, (SCM)cb);
57 SCM_SETCAR (z, (SCM)callback_tag);
59 return z;
63 Cxx_function
64 unsmob_cxx_function (SCM x)
67 if (SCM_NIMP (x) && SCM_CELL_TYPE(x) == callback_tag)
68 return (Cxx_function) SCM_CELL_WORD_1(x);
69 else
70 return 0;