File: sec-wrapping-defs-files.html

package info (click to toggle)
gtkmm-documentation 4.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 25,772 kB
  • sloc: cpp: 15,541; javascript: 1,208; makefile: 1,080; python: 401; xml: 106; perl: 67; sh: 8
file content (168 lines) | stat: -rw-r--r-- 7,832 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="highlight.min.css">
<script src="highlight.min.js"></script><script>
      hljs.configure({languages: ['cpp']});
      hljs.highlightAll();
    </script><title>Generating the .defs files.</title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
<link rel="home" href="index.html" title="Programming with gtkmm 4">
<link rel="up" href="chapter-wrapping-c-libraries.html" title="Appendix G. Wrapping C Libraries with gmmproc">
<link rel="prev" href="chapter-wrapping-c-libraries.html" title="Appendix G. Wrapping C Libraries with gmmproc">
<link rel="next" href="sec-wrapping-hg-files.html" title="The .hg and .ccg files">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Generating the .defs files.</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="chapter-wrapping-c-libraries.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<th width="60%" align="center">Appendix G. Wrapping C Libraries with gmmproc</th>
<td width="20%" align="right"> <a accesskey="n" href="sec-wrapping-hg-files.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
</table>
<hr>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="sec-wrapping-defs-files"></a>Generating the .defs files.</h2></div></div></div>


<p>The <code class="filename">.defs</code> files are text files, in a lisp format, that describe the API
  of a C library, including its
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p>objects (GObjects, widgets, interfaces, boxed-types and plain structs)</p></li>
<li class="listitem"><p>functions</p></li>
<li class="listitem"><p>enums</p></li>
<li class="listitem"><p>signals</p></li>
<li class="listitem"><p>properties</p></li>
<li class="listitem"><p>vfuncs</p></li>
</ul></div>
<p>
</p>
<p>At the moment, we have separate tools for generating different parts of
  these <code class="filename">.defs</code>, so we split them up into separate files.
  For instance, in the <code class="filename">gtk/src</code> directory of the <span class="application">gtkmm</span>
  sources, you will find these files:
    </p>
<div class="variablelist"><dl class="variablelist">
<dt><span class="term"><code class="filename">gtk.defs</code></span></dt>
<dd><p>Includes the other files.</p></dd>
<dt><span class="term"><code class="filename">gtk_methods.defs</code></span></dt>
<dd><p>Objects and functions.</p></dd>
<dt><span class="term"><code class="filename">gtk_enums.defs</code></span></dt>
<dd><p>Enumerations.</p></dd>
<dt><span class="term"><code class="filename">gtk_signals.defs</code></span></dt>
<dd><p>Signals and properties.</p></dd>
<dt><span class="term"><code class="filename">gtk_vfuncs.defs</code></span></dt>
<dd><p>vfuncs (function pointer member fields in structs), written by hand.</p></dd>
</dl></div>
<p>
</p>
<p>The <code class="filename">skeletonmm/tools/generate_defs_and_docs.sh</code> script
generates all <code class="filename">.defs</code> files and the <code class="filename">*_docs.xml</code> file,
described in the <a class="link" href="sec-wrapping-documentation.html" title="Documentation">Documentation</a> section.
</p>

<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="generating-defs-methods"></a>Generating the methods .defs</h3></div></div></div>


<p>This <code class="filename">.defs</code> file describes objects and their functions.
  It is generated by the <span class="command"><strong>h2def.py</strong></span> script which you can find in
  glibmm's <code class="filename">tools/defs_gen</code> directory. For instance,
</p>
<pre class="programlisting"><code class="code">$ ./h2def.py /usr/include/gtk-4.0/gtk/*.h &gt; gtk_methods.defs
</code></pre>
</div>

<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="generating-defs-enums"></a>Generating the enums .defs</h3></div></div></div>


<p>This <code class="filename">.defs</code> file describes enum types and their possible
  values. It is generated by the <code class="filename">enumextract.py</code> script which you can
  also find in glibmm's <code class="filename">tools/defs_gen</code> directory. For instance,
</p>
<pre class="programlisting"><code class="code">$ ./enumextract.py /usr/include/gtk-4.0/gtk/*.h &gt; gtk_enums.defs
</code></pre>
</div>

<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="generating-defs-signals-properties"></a>Generating the signals and properties .defs</h3></div></div></div>


<p>This <code class="filename">.defs</code> file describes signals and properties. It is
  generated by the special <code class="filename">generate_extra_defs</code> utility that is in every
  wrapping project, such as <code class="filename">gtkmm/tools/extra_defs_gen/</code>.
  For instance
</p>
<pre class="programlisting"><code class="code">$ cd tools/extra_defs_gen
$ ./generate_extra_defs &gt; gtk_signals.defs
</code></pre>
<p>You must edit the source code of your own <code class="filename">generate_extra_defs</code> tool
  in order to generate the <code class="filename">.defs</code> for the GObject C types that you wish to
  wrap. In the skeleton source tree, the source file is named
  <code class="filename">tools/extra_defs_gen/generate_defs_skeleton.cc</code>. If not done so
  already, the file should be renamed, with the basename of your new binding substituted
  for the <code class="varname">skeleton</code> placeholder. The <code class="filename">tools/extra_defs_gen/meson.build</code>
  file should also mention the new source filename.</p>
<p>Then edit the <code class="filename">.cc</code> file to specify the correct types.
  For instance, your <code class="function">main()</code> function might look like this:
</p>
<pre class="programlisting"><code class="code">#include &lt;glibmm_generate_extra_defs/generate_extra_defs.h&gt;
#include &lt;libsomething.h&gt;
#include &lt;iostream&gt;

int main(int, char**)
{
  something_init();

  std::cout &lt;&lt; get_defs(SOME_TYPE_WIDGET)
            &lt;&lt; get_defs(SOME_TYPE_STUFF);
  return 0;
}
</code></pre>
</div>

<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="writing-defs-vfuncs"></a>Writing the vfuncs .defs</h3></div></div></div>


<p>
  This <code class="filename">.defs</code> file describes virtual functions (vfuncs).
  It must be written by hand. There is the skeleton file
  <code class="filename">skeleton/src/skeleton_vfunc.defs</code> to start from. You can also look
  at <span class="application">gtkmm</span>'s <code class="filename">gtk/src/gtk_vfuncs.defs</code> file.
</p>
</div>

</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="chapter-wrapping-c-libraries.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<td width="20%" align="center"><a accesskey="u" href="chapter-wrapping-c-libraries.html"><img src="icons/up.png" alt="Up"></a></td>
<td width="40%" align="right"> <a accesskey="n" href="sec-wrapping-hg-files.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Appendix G. Wrapping C Libraries with gmmproc </td>
<td width="20%" align="center"><a accesskey="h" href="index.html"><img src="icons/home.png" alt="Home"></a></td>
<td width="40%" align="right" valign="top"> The .hg and .ccg files</td>
</tr>
</table>
</div>
</body>
</html>