You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 4.x/_sources/bindings/callbacks.rst.txt
+7-5Lines changed: 7 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -91,7 +91,9 @@ Remember that C style callbacks are simply function pointers, they do not have a
91
91
92
92
Simple Callback
93
93
"""""""""""""""
94
-
In the simplest case, a callback is only used once in a code base. Thus the ``Proc`` can be associated with the function pointer type. This is exactly what Rice does via the `NativeCallbackSimple <https://github.com/ruby-rice/rice/blob/master/rice/detail/NativeCallbackSimple.hpp>`_ template. Each callback signature creates a new C++ class from the NativeCallback template. The created class has a static member field that stores the ``Proc``.
94
+
In the simplest case, a callback is only used once in a code base. Thus there is a one-to-one mapping between a callback and its associated Ruby ``Proc``.
95
+
96
+
This is easy to implement - Rice generates a new C++ class based on the callback's signature using the `NativeCallbackSimple <https://github.com/ruby-rice/rice/blob/master/rice/detail/NativeCallbackSimple.hpp>`_ class template. The generated class has a static member field that stores the ``Proc``. Thus every callback is associated with a single instantiation of the `NativeCallbackSimple` template.
95
97
96
98
LibFFI Callback
97
99
"""""""""""""""
@@ -102,10 +104,10 @@ However, a library often times use a callback in multiple places. For example:
The above code uses the same callback type 3 different times, thus the one-to-one mapping between callback type and C++ class is broken. Intead, we want a callback type to map to 3 different Ruby ``Procs``.
107
+
The above code uses the same callback type 3 different times, thus the one-to-one mapping between callback type and C++ class is broken. Therefore the simple solution of using a static member variable to store the Ruby proc no longer works. Instead, we need to store 3 different ``Procs`` and figure out which one to call when the callback is invoked.
106
108
107
-
In this case, Ruby can use libffi's `closure <https://github.com/libffi/libffi/blob/master/src/closures.c>`_ API. The closure API associates a piece of user datawith a callback and then dynamically generates a new function that the callback invokes.
109
+
In this case, Rice uses libffi's `closure <https://github.com/libffi/libffi/blob/master/src/closures.c>`_ API. The closure API associates a piece of user data, in this case the ``Proc``, with a callback and then dynamically generates a new function which is what is invoked by the callback function.
108
110
109
-
Since you are working with Ruby, it is highly likely that you have LibFFI installed since the `Fiddle <https://github.com/ruby/fiddle>`_ gem requires it. The default build script will check for LibFFI and if it is found compile it into your bindings.
111
+
Since you are working with Ruby, it is highly likely that LibFFI is already installed since the `Fiddle <https://github.com/ruby/fiddle>`_ gem requires it. The default build script will check for LibFFI and if it is found compile it into your bindings.
110
112
111
-
If you are using CMake, you will need to define a C++ preprocessor define called ``HAVE_LIBFFI`` and link to libffi.
113
+
If you are using CMake, you will need to add a C++ preprocessor define called ``HAVE_LIBFFI`` and link to libffi.
Copy file name to clipboardExpand all lines: 4.x/_sources/bindings/operators.rst.txt
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -126,7 +126,7 @@ C++ classes that support the ``()`` operator are known as functors. Ruby support
126
126
127
127
Conversion Operators
128
128
--------------------
129
-
C++ allows uses to create both explicit and implicit converion operators or functions. These are used to convert a class to a different types. For example:
129
+
C++ allows users to define explicit and implicit conversion operators or functions. These are used to convert a class to a different types. For example:
Copy file name to clipboardExpand all lines: 4.x/bindings/callbacks.html
+6-5Lines changed: 6 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -360,7 +360,8 @@ <h3>Associating Callbacks with Procs<a class="headerlink" href="#associating-cal
360
360
<p>Remember that C style callbacks are simply function pointers, they do not have a place to store any state. Thus when a C style callback is invoked, Rice needs to determine what Ruby <codeclass="docutils literal notranslate"><spanclass="pre">Proc</span></code> to call. This is a tricky problem to solve.</p>
361
361
<sectionid="simple-callback">
362
362
<h4>Simple Callback<aclass="headerlink" href="#simple-callback" title="Link to this heading">¶</a></h4>
363
-
<p>In the simplest case, a callback is only used once in a code base. Thus the <codeclass="docutils literal notranslate"><spanclass="pre">Proc</span></code> can be associated with the function pointer type. This is exactly what Rice does via the <aclass="reference external" href="https://github.com/ruby-rice/rice/blob/master/rice/detail/NativeCallbackSimple.hpp">NativeCallbackSimple</a> template. Each callback signature creates a new C++ class from the NativeCallback template. The created class has a static member field that stores the <codeclass="docutils literal notranslate"><spanclass="pre">Proc</span></code>.</p>
363
+
<p>In the simplest case, a callback is only used once in a code base. Thus there is a one-to-one mapping between a callback and its associated Ruby <codeclass="docutils literal notranslate"><spanclass="pre">Proc</span></code>.</p>
364
+
<p>This is easy to implement - Rice generates a new C++ class based on the callback’s signature using the <aclass="reference external" href="https://github.com/ruby-rice/rice/blob/master/rice/detail/NativeCallbackSimple.hpp">NativeCallbackSimple</a> class template. The generated class has a static member field that stores the <codeclass="docutils literal notranslate"><spanclass="pre">Proc</span></code>. Thus every callback is associated with a single instantiation of the <cite>NativeCallbackSimple</cite> template.</p>
364
365
</section>
365
366
<sectionid="libffi-callback">
366
367
<h4>LibFFI Callback<aclass="headerlink" href="#libffi-callback" title="Link to this heading">¶</a></h4>
@@ -369,10 +370,10 @@ <h4>LibFFI Callback<a class="headerlink" href="#libffi-callback" title="Link to
<p>The above code uses the same callback type 3 different times, thus the one-to-one mapping between callback type and C++ class is broken. Intead, we want a callback type to map to 3 different Ruby <codeclass="docutils literal notranslate"><spanclass="pre">Procs</span></code>.</p>
373
-
<p>In this case, Ruby can use libffi’s <aclass="reference external" href="https://github.com/libffi/libffi/blob/master/src/closures.c">closure</a> API. The closure API associates a piece of user datawith a callback and then dynamically generates a new function that the callback invokes.</p>
374
-
<p>Since you are working with Ruby, it is highly likely that you have LibFFI installed since the <aclass="reference external" href="https://github.com/ruby/fiddle">Fiddle</a> gem requires it. The default build script will check for LibFFI and if it is found compile it into your bindings.</p>
375
-
<p>If you are using CMake, you will need to define a C++ preprocessor define called <codeclass="docutils literal notranslate"><spanclass="pre">HAVE_LIBFFI</span></code> and link to libffi.</p>
373
+
<p>The above code uses the same callback type 3 different times, thus the one-to-one mapping between callback type and C++ class is broken. Therefore the simple solution of using a static member variable to store the Ruby proc no longer works. Instead, we need to store 3 different <codeclass="docutils literal notranslate"><spanclass="pre">Procs</span></code> and figure out which one to call when the callback is invoked.</p>
374
+
<p>In this case, Rice uses libffi’s <aclass="reference external" href="https://github.com/libffi/libffi/blob/master/src/closures.c">closure</a> API. The closure API associates a piece of user data, in this case the <codeclass="docutils literal notranslate"><spanclass="pre">Proc</span></code>, with a callback and then dynamically generates a new function which is what is invoked by the callback function.</p>
375
+
<p>Since you are working with Ruby, it is highly likely that LibFFI is already installed since the <aclass="reference external" href="https://github.com/ruby/fiddle">Fiddle</a> gem requires it. The default build script will check for LibFFI and if it is found compile it into your bindings.</p>
376
+
<p>If you are using CMake, you will need to add a C++ preprocessor define called <codeclass="docutils literal notranslate"><spanclass="pre">HAVE_LIBFFI</span></code> and link to libffi.</p>
Copy file name to clipboardExpand all lines: 4.x/bindings/operators.html
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -506,7 +506,7 @@ <h2>Other Operators<a class="headerlink" href="#other-operators" title="Link to
506
506
</section>
507
507
<sectionid="conversion-operators">
508
508
<h2>Conversion Operators<aclass="headerlink" href="#conversion-operators" title="Link to this heading">¶</a></h2>
509
-
<p>C++ allows uses to create both explicit and implicit converion operators or functions. These are used to convert a class to a different types. For example:</p>
509
+
<p>C++ allows users to define explicit and implicit conversion operators or functions. These are used to convert a class to a different types. For example:</p>
0 commit comments