rice 1.7.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Doxyfile +1 -1
- data/Makefile.in +29 -18
- data/README +59 -129
- data/aclocal.m4 +32 -29
- data/config.guess +103 -217
- data/config.sub +42 -25
- data/configure +10 -14
- data/depcomp +3 -2
- data/extconf.rb +39 -21
- data/install-sh +170 -196
- data/missing +3 -3
- data/rice/Makefile.am +0 -5
- data/rice/Makefile.in +21 -15
- data/rice/detail/env.hpp +0 -8
- data/rice/detail/method_data.cpp +0 -20
- data/rice/detail/ruby.hpp +0 -13
- data/rice/detail/ruby_version_code.hpp +1 -1
- data/ruby.ac +3 -8
- data/ruby/Makefile.in +17 -5
- data/ruby/lib/Makefile.in +17 -6
- data/ruby/lib/mkmf-rice.rb.in +9 -13
- data/ruby/lib/version.rb +1 -1
- data/sample/Makefile.am +4 -4
- data/sample/Makefile.in +21 -9
- data/test/Makefile.am +2 -7
- data/test/Makefile.in +32 -41
- data/test/ext/Makefile.am +12 -14
- data/test/ext/Makefile.in +29 -19
- data/test/test_To_From_Ruby.cpp +6 -0
- data/test/test_rice.rb +0 -4
- metadata +3 -12
- data/rice/Critical_Guard.hpp +0 -40
- data/rice/Critical_Guard.ipp +0 -26
- data/rice/VM.cpp +0 -82
- data/rice/VM.hpp +0 -32
- data/rice/detail/mininode.cpp +0 -1220
- data/rice/detail/mininode.hpp +0 -320
- data/rice/detail/rubysig.hpp +0 -19
- data/test/test_Critical_Guard.cpp +0 -51
- data/test/test_VM.cpp +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b48f6fad0387e0af0b875368cf76cc7fefd0fb9
|
4
|
+
data.tar.gz: 23bc4f4e7bd5c9cba4e261259c15bd932d979abc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05f85e6ae14093a830d4aea7aa509b8c6dce523ac0297b1036a930e9319f5ce5dfd817fa40a1046231a4728ca02dc25c73d26675d4ff7d001b51567914ebad8c
|
7
|
+
data.tar.gz: a8462693ca9aa5e01645fa0177574902c834f4b23253d5a1ba8d50a471367cc7b22e998c3fa568537090c598cfc60d0a6f09e9ec69dd24d88b36a11552751cfd
|
data/Doxyfile
CHANGED
@@ -38,7 +38,7 @@ PROJECT_NAME = "Rice"
|
|
38
38
|
# could be handy for archiving the generated documentation or if some version
|
39
39
|
# control system is used.
|
40
40
|
|
41
|
-
PROJECT_NUMBER =
|
41
|
+
PROJECT_NUMBER = 2.0.0
|
42
42
|
|
43
43
|
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
44
44
|
# for a project that appears at the top of each page and should give viewer a
|
data/Makefile.in
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
# Makefile.in generated by automake 1.
|
1
|
+
# Makefile.in generated by automake 1.15 from Makefile.am.
|
2
2
|
# @configure_input@
|
3
3
|
|
4
|
-
# Copyright (C) 1994-
|
4
|
+
# Copyright (C) 1994-2014 Free Software Foundation, Inc.
|
5
5
|
|
6
6
|
# This Makefile.in is free software; the Free Software Foundation
|
7
7
|
# gives unlimited permission to copy and/or distribute it,
|
@@ -44,7 +44,17 @@
|
|
44
44
|
#
|
45
45
|
# This is usually added to MOSTLYCLEANFILES.
|
46
46
|
VPATH = @srcdir@
|
47
|
-
am__is_gnu_make =
|
47
|
+
am__is_gnu_make = { \
|
48
|
+
if test -z '$(MAKELEVEL)'; then \
|
49
|
+
false; \
|
50
|
+
elif test -n '$(MAKE_HOST)'; then \
|
51
|
+
true; \
|
52
|
+
elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
|
53
|
+
true; \
|
54
|
+
else \
|
55
|
+
false; \
|
56
|
+
fi; \
|
57
|
+
}
|
48
58
|
am__make_running_with_option = \
|
49
59
|
case $${target_option-} in \
|
50
60
|
?) ;; \
|
@@ -107,11 +117,6 @@ PRE_UNINSTALL = :
|
|
107
117
|
POST_UNINSTALL = :
|
108
118
|
build_triplet = @build@
|
109
119
|
host_triplet = @host@
|
110
|
-
DIST_COMMON = $(srcdir)/doxygen.am $(srcdir)/Makefile.in \
|
111
|
-
$(srcdir)/Makefile.am $(top_srcdir)/configure \
|
112
|
-
$(am__configure_deps) \
|
113
|
-
$(top_srcdir)/rice/detail/ruby_version_code.hpp.in COPYING \
|
114
|
-
README TODO config.guess config.sub depcomp install-sh missing
|
115
120
|
subdir = .
|
116
121
|
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
117
122
|
am__aclocal_m4_deps = $(top_srcdir)/check_stdcxx_11.ac \
|
@@ -119,6 +124,8 @@ am__aclocal_m4_deps = $(top_srcdir)/check_stdcxx_11.ac \
|
|
119
124
|
$(top_srcdir)/configure.ac
|
120
125
|
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
121
126
|
$(ACLOCAL_M4)
|
127
|
+
DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \
|
128
|
+
$(am__configure_deps) $(am__DIST_COMMON)
|
122
129
|
am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
|
123
130
|
configure.lineno config.status.lineno
|
124
131
|
mkinstalldirs = $(install_sh) -d
|
@@ -181,6 +188,9 @@ ETAGS = etags
|
|
181
188
|
CTAGS = ctags
|
182
189
|
CSCOPE = cscope
|
183
190
|
DIST_SUBDIRS = $(SUBDIRS)
|
191
|
+
am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/doxygen.am \
|
192
|
+
$(top_srcdir)/rice/detail/ruby_version_code.hpp.in COPYING \
|
193
|
+
README TODO config.guess config.sub depcomp install-sh missing
|
184
194
|
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
185
195
|
distdir = $(PACKAGE)-$(VERSION)
|
186
196
|
top_distdir = "$(distdir)"
|
@@ -413,7 +423,6 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(srcdir)/doxygen.am $(am__configu
|
|
413
423
|
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign Makefile'; \
|
414
424
|
$(am__cd) $(top_srcdir) && \
|
415
425
|
$(AUTOMAKE) --foreign Makefile
|
416
|
-
.PRECIOUS: Makefile
|
417
426
|
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
418
427
|
@case '$?' in \
|
419
428
|
*config.status*) \
|
@@ -423,7 +432,7 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
|
423
432
|
echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)'; \
|
424
433
|
cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe);; \
|
425
434
|
esac;
|
426
|
-
$(srcdir)/doxygen.am:
|
435
|
+
$(srcdir)/doxygen.am $(am__empty):
|
427
436
|
|
428
437
|
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
|
429
438
|
$(SHELL) ./config.status --recheck
|
@@ -623,15 +632,15 @@ dist-xz: distdir
|
|
623
632
|
$(am__post_remove_distdir)
|
624
633
|
|
625
634
|
dist-tarZ: distdir
|
626
|
-
@echo WARNING: "Support for
|
627
|
-
|
635
|
+
@echo WARNING: "Support for distribution archives compressed with" \
|
636
|
+
"legacy program 'compress' is deprecated." >&2
|
628
637
|
@echo WARNING: "It will be removed altogether in Automake 2.0" >&2
|
629
638
|
tardir="$(distdir)" && $(am__tar) | compress -c >"$(distdir)".tar.Z
|
630
639
|
$(am__post_remove_distdir)
|
631
640
|
|
632
641
|
dist-shar: distdir
|
633
|
-
@echo WARNING: "Support for distribution archives
|
634
|
-
|
642
|
+
@echo WARNING: "Support for shar distribution archives is" \
|
643
|
+
"deprecated." >&2
|
635
644
|
@echo WARNING: "It will be removed altogether in Automake 2.0" >&2
|
636
645
|
shar "$(distdir)" | GZIP=$(GZIP_ENV) gzip -c >"$(distdir)".shar.gz
|
637
646
|
$(am__post_remove_distdir)
|
@@ -667,17 +676,17 @@ distcheck: dist
|
|
667
676
|
esac
|
668
677
|
chmod -R a-w "$(distdir)"
|
669
678
|
chmod u+w "$(distdir)"
|
670
|
-
mkdir "$(distdir)"/_build "$(distdir)"/_inst
|
679
|
+
mkdir "$(distdir)"/_build "$(distdir)"/_build/sub "$(distdir)"/_inst
|
671
680
|
chmod a-w "$(distdir)"
|
672
681
|
test -d "$(distdir)"/_build || exit 0; \
|
673
682
|
dc_install_base=`$(am__cd) "$(distdir)"/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \
|
674
683
|
&& dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \
|
675
684
|
&& am__cwd=`pwd` \
|
676
|
-
&& $(am__cd) "$(distdir)"/_build \
|
677
|
-
&&
|
685
|
+
&& $(am__cd) "$(distdir)"/_build/sub \
|
686
|
+
&& ../../configure \
|
678
687
|
$(AM_DISTCHECK_CONFIGURE_FLAGS) \
|
679
688
|
$(DISTCHECK_CONFIGURE_FLAGS) \
|
680
|
-
--srcdir
|
689
|
+
--srcdir=../.. --prefix="$$dc_install_base" \
|
681
690
|
&& $(MAKE) $(AM_MAKEFLAGS) \
|
682
691
|
&& $(MAKE) $(AM_MAKEFLAGS) dvi \
|
683
692
|
&& $(MAKE) $(AM_MAKEFLAGS) check \
|
@@ -851,6 +860,8 @@ uninstall-am:
|
|
851
860
|
maintainer-clean-generic mostlyclean mostlyclean-generic pdf \
|
852
861
|
pdf-am ps ps-am tags tags-am uninstall uninstall-am
|
853
862
|
|
863
|
+
.PRECIOUS: Makefile
|
864
|
+
|
854
865
|
|
855
866
|
@DX_COND_doc_TRUE@@DX_COND_ps_TRUE@doxygen-ps: @DX_DOCDIR@/@PACKAGE@.ps
|
856
867
|
|
data/README
CHANGED
@@ -21,8 +21,6 @@ The source is hosted on github: http://github.com/jasonroelofs/rice
|
|
21
21
|
|
22
22
|
Bug tracking: http://github.com/jasonroelofs/rice/issues
|
23
23
|
|
24
|
-
Mailing List: rice@librelist.com (your first email will be used as a subscription request and dropped)
|
25
|
-
|
26
24
|
\section installation Installation
|
27
25
|
|
28
26
|
\code
|
@@ -40,13 +38,6 @@ Building it locally from a clone of the repository is as follows:
|
|
40
38
|
Rice is known to work on *nix and OSX. Windows is not currently
|
41
39
|
supported.
|
42
40
|
|
43
|
-
Rice does not work with any Ruby compiled with the Falcon
|
44
|
-
performans patches as they make changes to some internals which Rice
|
45
|
-
relies on.
|
46
|
-
|
47
|
-
Also Rice requires a Ruby built with --enable-shared and will not
|
48
|
-
install properly against a Ruby with only static libraries.
|
49
|
-
|
50
41
|
\section tutorial Tutorial
|
51
42
|
|
52
43
|
\subsection geting_started Getting started
|
@@ -69,13 +60,13 @@ Next we create our extension and save it to test.cpp:
|
|
69
60
|
|
70
61
|
\code
|
71
62
|
extern "C"
|
72
|
-
void
|
63
|
+
void Init_test()
|
73
64
|
{
|
74
65
|
}
|
75
66
|
\endcode
|
76
67
|
|
77
68
|
Note the extern "C" line above. This tells the compiler that the
|
78
|
-
function
|
69
|
+
function Init_test should have C linkage and calling convention. This
|
79
70
|
turns off name mangling so that the Ruby interpreter will be able to
|
80
71
|
find the function (remember that Ruby is written in C, not C++).
|
81
72
|
|
@@ -94,7 +85,7 @@ Defining a class in Rice is easy:
|
|
94
85
|
using namespace Rice;
|
95
86
|
|
96
87
|
extern "C"
|
97
|
-
void
|
88
|
+
void Init_test()
|
98
89
|
{
|
99
90
|
Class rb_cTest = define_class("Test");
|
100
91
|
}
|
@@ -109,7 +100,7 @@ wanted to inherit from a different class, we could easily do so:
|
|
109
100
|
using namespace Rice;
|
110
101
|
|
111
102
|
extern "C"
|
112
|
-
void
|
103
|
+
void Init_test()
|
113
104
|
{
|
114
105
|
Class rb_cMySocket = define_class("MySocket", rb_cIO);
|
115
106
|
}
|
@@ -153,7 +144,7 @@ Now let's add a method to our class:
|
|
153
144
|
}
|
154
145
|
|
155
146
|
extern "C"
|
156
|
-
void
|
147
|
+
void Init_test()
|
157
148
|
{
|
158
149
|
Class rb_cTest =
|
159
150
|
define_class("Test")
|
@@ -185,7 +176,7 @@ We could also add an #initialize method to our class:
|
|
185
176
|
}
|
186
177
|
|
187
178
|
extern "C"
|
188
|
-
void
|
179
|
+
void Init_test()
|
189
180
|
{
|
190
181
|
Class rb_cTest =
|
191
182
|
define_class("Test")
|
@@ -230,7 +221,7 @@ section. To wrap it:
|
|
230
221
|
using namespace Rice;
|
231
222
|
|
232
223
|
extern "C"
|
233
|
-
void
|
224
|
+
void Init_test()
|
234
225
|
{
|
235
226
|
Data_Type<Test> rb_cTest =
|
236
227
|
define_class<Test>("Test")
|
@@ -242,11 +233,10 @@ section. To wrap it:
|
|
242
233
|
This example is similar to the one before, but we use Data_Type<>
|
243
234
|
instead of Class and the template version of define_class() instead of
|
244
235
|
the non-template version. This creates a binding in the Rice library
|
245
|
-
between the Ruby class Test and the C++ class Test
|
246
|
-
member function pointers to define_method()
|
247
|
-
automatically.
|
236
|
+
between the Ruby class Test and the C++ class Test such that Rice passes
|
237
|
+
member function pointers to define_method().
|
248
238
|
|
249
|
-
It
|
239
|
+
It is possible to write the conversion functions ourself (as we'll see
|
250
240
|
below), but Rice does all the dirty work for us.
|
251
241
|
|
252
242
|
|
@@ -312,7 +302,7 @@ Take another look at the wrapper we wrote for the Test class:
|
|
312
302
|
|
313
303
|
\code
|
314
304
|
extern "C"
|
315
|
-
void
|
305
|
+
void Init_test()
|
316
306
|
{
|
317
307
|
Data_Type<Test> rb_cTest =
|
318
308
|
define_class<Test>("Test")
|
@@ -393,7 +383,7 @@ If we were to wrap this function:
|
|
393
383
|
|
394
384
|
\code
|
395
385
|
extern "C"
|
396
|
-
void
|
386
|
+
void Init_test()
|
397
387
|
{
|
398
388
|
Data_Type<Test> rb_cTest =
|
399
389
|
define_class<Test>("Test")
|
@@ -412,13 +402,13 @@ and call it from inside Ruby:
|
|
412
402
|
|
413
403
|
we would get an exception. Rice will automatically convert any
|
414
404
|
C++ exception it catches into a Ruby exception. But what if we wanted
|
415
|
-
to use a custom
|
405
|
+
to use a custom error message when we convert the exception, or what if
|
416
406
|
we wanted to convert to a different type of exception? We can write
|
417
407
|
this:
|
418
408
|
|
419
409
|
\code
|
420
410
|
extern "C"
|
421
|
-
void
|
411
|
+
void Init_test()
|
422
412
|
{
|
423
413
|
Data_Type<Test> rb_cTest =
|
424
414
|
define_class<Test>("Test")
|
@@ -457,7 +447,7 @@ Rice uses a similar class called Jump_Tag to handle symbols thrown by
|
|
457
447
|
Ruby's throw/catch or other non-local jumps from inside the Ruby VM.
|
458
448
|
|
459
449
|
|
460
|
-
\subsection builtin Builtin
|
450
|
+
\subsection builtin Builtin Types
|
461
451
|
|
462
452
|
You've seen this example:
|
463
453
|
|
@@ -466,8 +456,8 @@ You've seen this example:
|
|
466
456
|
std::cout << object_id << std::endl;
|
467
457
|
\endcode
|
468
458
|
|
469
|
-
Rice mimics the Ruby class hierarchy as closely as it can
|
470
|
-
|
459
|
+
Rice mimics the Ruby class hierarchy as closely as it can.
|
460
|
+
In fact, the above code also works for Classes:
|
471
461
|
|
472
462
|
\code
|
473
463
|
Class rb_cTest = define_class<Test>("Test");
|
@@ -528,7 +518,7 @@ Forunately Rice handles this gracefully:
|
|
528
518
|
};
|
529
519
|
|
530
520
|
extern "C"
|
531
|
-
void
|
521
|
+
void Init_test()
|
532
522
|
{
|
533
523
|
Data_Type<Base> rb_cBase =
|
534
524
|
define_class<Base>("Base")
|
@@ -541,8 +531,7 @@ Forunately Rice handles this gracefully:
|
|
541
531
|
The second template parameter to define_class indicates that Derived
|
542
532
|
inherits from Base.
|
543
533
|
|
544
|
-
Rice does not
|
545
|
-
this is possible through the use of mixins.
|
534
|
+
Rice does not support multiple inheritance.
|
546
535
|
|
547
536
|
|
548
537
|
\subsection overloading Overloaded functions
|
@@ -577,13 +566,11 @@ We can wrap this class by using typedefs:
|
|
577
566
|
}
|
578
567
|
\endcode
|
579
568
|
|
580
|
-
A future version of Rice may provide a simplified interface for this.
|
581
|
-
|
582
569
|
|
583
570
|
\subsection user_defined_conversions User-defined type conversions
|
584
571
|
|
585
572
|
Rice provides default conversions for many built-in types. Sometimes,
|
586
|
-
however, the default conversion is not
|
573
|
+
however, the default conversion is not what is expected. For
|
587
574
|
example, consider a function:
|
588
575
|
|
589
576
|
\code
|
@@ -605,7 +592,7 @@ If we write this:
|
|
605
592
|
|
606
593
|
\code
|
607
594
|
extern "C"
|
608
|
-
void
|
595
|
+
void Init_test()
|
609
596
|
{
|
610
597
|
define_global_function("foo", &foo);
|
611
598
|
}
|
@@ -624,7 +611,7 @@ To avoid this problem, it is necessary to write a wrapper function:
|
|
624
611
|
}
|
625
612
|
|
626
613
|
extern "C"
|
627
|
-
void
|
614
|
+
void Init_test()
|
628
615
|
{
|
629
616
|
define_global_function("foo", &wrap_foo);
|
630
617
|
}
|
@@ -633,13 +620,11 @@ To avoid this problem, it is necessary to write a wrapper function:
|
|
633
620
|
Note that the out parameter is returned from wrap_foo, as Ruby does not
|
634
621
|
have pass-by-variable-reference (it uses pass-by-object-reference).
|
635
622
|
|
636
|
-
Future versions of Rice will have a cleaner way of dealing with this.
|
637
|
-
|
638
623
|
|
639
624
|
\subsection default_arguments Default Arguments
|
640
625
|
|
641
626
|
Going back to our initial C++ class example, lets say that hello() now
|
642
|
-
|
627
|
+
takes more arguments, one of which has a default value:
|
643
628
|
|
644
629
|
\code
|
645
630
|
class Test
|
@@ -651,7 +636,7 @@ take a few arguments for what to return, one which has a default value:
|
|
651
636
|
\endcode
|
652
637
|
|
653
638
|
As default parameter information is not available through templates,
|
654
|
-
it
|
639
|
+
it is necessary to define this in Rice explicitly using Rice::Arg:
|
655
640
|
|
656
641
|
\code
|
657
642
|
#include "rice/Data_Type.hpp"
|
@@ -660,7 +645,7 @@ it's necessary to define this in Rice explicitly using Rice::Arg:
|
|
660
645
|
using namespace Rice;
|
661
646
|
|
662
647
|
extern "C"
|
663
|
-
void
|
648
|
+
void Init_test()
|
664
649
|
{
|
665
650
|
Data_Type<Test> rb_cTest =
|
666
651
|
define_class<Test>("Test")
|
@@ -673,16 +658,9 @@ it's necessary to define this in Rice explicitly using Rice::Arg:
|
|
673
658
|
\endcode
|
674
659
|
|
675
660
|
The syntax here is simply Arg(nameOfParameter)[ = defaultValue]. The name of the
|
676
|
-
parameter is not important (
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
These Rice::Arg objects must be in the correct order, and if there are more than
|
681
|
-
one of them they must be surrounded in parentheses, as above, or the compilation
|
682
|
-
will fail.
|
683
|
-
|
684
|
-
It may be required to explicitly cast the default argument values to their
|
685
|
-
appropriate types:
|
661
|
+
parameter is not important here (a readability tool), but the value set via operator=
|
662
|
+
must match the type of the parameter. As such it may be necessary to
|
663
|
+
explicitly cast the default value.
|
686
664
|
|
687
665
|
\code
|
688
666
|
.define_method("hello",
|
@@ -691,7 +669,10 @@ appropriate types:
|
|
691
669
|
);
|
692
670
|
\endcode
|
693
671
|
|
694
|
-
|
672
|
+
These Rice::Arg objects must be in the correct order and must be
|
673
|
+
surrounded with parentheses if more than one exists.
|
674
|
+
|
675
|
+
Now, Ruby will now know about the default arguments, and this wrapper
|
695
676
|
can be used as expected:
|
696
677
|
|
697
678
|
\code
|
@@ -700,7 +681,7 @@ can be used as expected:
|
|
700
681
|
t.hello("goodnight", "moon")
|
701
682
|
\endcode
|
702
683
|
|
703
|
-
This
|
684
|
+
This also works with Constructors:
|
704
685
|
|
705
686
|
\code
|
706
687
|
.define_constructor(Constructor<SomeClass, int, int>(),
|
@@ -710,11 +691,11 @@ This will also work with Constructors:
|
|
710
691
|
\subsection director Director
|
711
692
|
|
712
693
|
As polymorphism is the most important tennant of Object Oriented Programming,
|
713
|
-
it
|
694
|
+
it is important that Rice supports polymorphic calls travelling between C++
|
714
695
|
and Ruby seemlessly. Super calls from Ruby subclasses back into C++ already work,
|
715
|
-
but enabling the other direction requires some extra
|
716
|
-
|
717
|
-
Rice::Data_Type::define_director
|
696
|
+
but enabling the other direction requires some extra effort. Rice
|
697
|
+
suppplies the the Rice::Director class and
|
698
|
+
Rice::Data_Type::define_director to expose this functionality.
|
718
699
|
|
719
700
|
Like SWIG_Director, Rice::Director is a class that is used to build a proxy class
|
720
701
|
to properly send execution up or down the object heiarchy for that class. Take
|
@@ -730,13 +711,12 @@ the following class:
|
|
730
711
|
\endcode
|
731
712
|
|
732
713
|
Due to the abstract nature of this class, it will not work at all with Rice
|
733
|
-
in
|
714
|
+
in its current form. Any attempt to do so will cause a compilation error due to
|
734
715
|
this class not being constructable. Even without the pure virtual function, any
|
735
716
|
call to VirtualBase::doWork will stop at the C++ level and will not pass down into
|
736
717
|
any Ruby subclasses.
|
737
718
|
|
738
|
-
To properly wrap both of these methods,
|
739
|
-
that subclasses Rice::Director along with a few methods:
|
719
|
+
To properly wrap both of these methods, use a Rice::Director subclass as a proxy:
|
740
720
|
|
741
721
|
\code
|
742
722
|
#include "rice/Director.hpp"
|
@@ -769,7 +749,7 @@ There is a lot going on here, so we'll go through each part.
|
|
769
749
|
class VirtualBaseProxy : public Virtualbase, public Rice::Director {
|
770
750
|
\endcode
|
771
751
|
|
772
|
-
First, the class needs to subclass both the virtual class and Rice::Director
|
752
|
+
First, the class needs to subclass both the virtual class in question and Rice::Director.
|
773
753
|
|
774
754
|
\code
|
775
755
|
public:
|
@@ -777,10 +757,9 @@ First, the class needs to subclass both the virtual class and Rice::Director cla
|
|
777
757
|
\endcode
|
778
758
|
|
779
759
|
For Rice::Director to work its magic, every instance of this class needs to
|
780
|
-
have a handle to the Ruby instance
|
781
|
-
must take a Rice::Object as the first argument
|
782
|
-
|
783
|
-
minimum required for a Rice::Director proxy.
|
760
|
+
have a handle to the Ruby instance. The constructor
|
761
|
+
must take a Rice::Object as the first argument and pass it up into
|
762
|
+
Rice::Director. The code here is the minimum required for a Rice::Director proxy.
|
784
763
|
|
785
764
|
\code
|
786
765
|
virtual int doWork() {
|
@@ -792,11 +771,12 @@ minimum required for a Rice::Director proxy.
|
|
792
771
|
}
|
793
772
|
\endcode
|
794
773
|
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
774
|
+
Here the directory proxy overrides the methods for Ruby exposure and
|
775
|
+
implements the required actions to pass flow around the heirarchy
|
776
|
+
appropriately. The pattern shown here is that the actual override will
|
777
|
+
call down into Ruby, handling any type conversions, while a
|
778
|
+
default_methodName method handles calling up into C++ and will be the
|
779
|
+
method wrapped into Rice.
|
800
780
|
|
801
781
|
The default_doWork method will be used as Rice's hookup of calling back up the
|
802
782
|
heirarchy (wrapping is below). This method needs to do one of two things: call
|
@@ -810,8 +790,8 @@ processWorker example:
|
|
810
790
|
\endcode
|
811
791
|
|
812
792
|
The method raisePureVirtual() exists to allow wrapping a pure virtual method into Ruby
|
813
|
-
but making sure any users of this extension are
|
814
|
-
in the C++
|
793
|
+
(and ensuring compliation is possible) but making sure any users of this extension are
|
794
|
+
informed quickly that there's nothing callable in the C++ side of the library.
|
815
795
|
|
816
796
|
Once the proxy class is built, it's time to wrap it into Ruby:
|
817
797
|
|
@@ -835,14 +815,14 @@ object construction / destruction of the types in question.
|
|
835
815
|
|
836
816
|
\subsection implicit_cast Implicit Casting
|
837
817
|
|
838
|
-
There are times when a library exposes classes that while unrelated are
|
839
|
-
built to be interchangeable across the library. One example of this
|
840
|
-
|
841
|
-
href="http://www.ogre3d.org/">OGRE</a
|
818
|
+
There are times when a library exposes classes that, while unrelated, are
|
819
|
+
built to be interchangeable across the library. One example of this is found in
|
820
|
+
the Open Source 3d rendering engine <a
|
821
|
+
href="http://www.ogre3d.org/">OGRE</a>: Ogre::Degree and Ogre::Radian.
|
842
822
|
When a given method takes a Radian, you're free to pass in a Degree, and vice versa.
|
843
823
|
|
844
824
|
Rice cannot automatically figure out if this kind of functionality is
|
845
|
-
possible in a given library but it does
|
825
|
+
possible in a given library but it does provide an API for defining
|
846
826
|
these relationships: Rice::define_implicit_cast<From, To>().
|
847
827
|
|
848
828
|
\code
|
@@ -861,12 +841,11 @@ void Init_implicit() {
|
|
861
841
|
}
|
862
842
|
\endcode
|
863
843
|
|
864
|
-
|
865
|
-
proper use:
|
844
|
+
Using Rice::define_implicit_cast has the following requirements:
|
866
845
|
|
867
846
|
\li The two types must be bound in Rice before defining the cast.
|
868
847
|
\li The classes must have constructors that take the other type.
|
869
|
-
\li This feature cannot be used with fundamental types
|
848
|
+
\li This feature cannot be used with fundamental types.
|
870
849
|
|
871
850
|
To see a full example of this feature, please check out
|
872
851
|
test/test_Data_Type.cpp.
|
@@ -1031,7 +1010,7 @@ to be much more readable than using the Boost preprocessor library.
|
|
1031
1010
|
|
1032
1011
|
\section history History
|
1033
1012
|
|
1034
|
-
Rice originated as a project to interface with C++-based trading
|
1013
|
+
Rice originated as Excruby, a project to interface with C++-based trading
|
1035
1014
|
software at Automated Trading Desk in Mount Pleasant, South Carolina.
|
1036
1015
|
The Ruby bindings for Swig were at the time less mature than they are
|
1037
1016
|
today, and did not suit the needs of the project.
|
@@ -1073,53 +1052,4 @@ clean up the object, the smart pointer will be destroyed, decrementing
|
|
1073
1052
|
the reference count; when the reference count drops to 0, underlying
|
1074
1053
|
object will be destroyed.
|
1075
1054
|
|
1076
|
-
|
1077
|
-
\section embedding Embedding
|
1078
|
-
|
1079
|
-
You can embed the Ruby interpter in your application by using the VM
|
1080
|
-
class:
|
1081
|
-
|
1082
|
-
\code
|
1083
|
-
int main(int argc, char * argv[])
|
1084
|
-
{
|
1085
|
-
Rice::VM vm(argc, argv);
|
1086
|
-
vm.run()
|
1087
|
-
}
|
1088
|
-
\endcode
|
1089
|
-
|
1090
|
-
If the VM is not initialized from main() -- from a callback, for example
|
1091
|
-
-- then you may need to initialize the stack whenever you use Rice or
|
1092
|
-
the Ruby API:
|
1093
|
-
|
1094
|
-
\code
|
1095
|
-
std::unique_ptr<Rice::VM> vm;
|
1096
|
-
Rice::Object obj;
|
1097
|
-
|
1098
|
-
void some_application_extension_init()
|
1099
|
-
{
|
1100
|
-
vm.reset(new Rice::VM("some_application"));
|
1101
|
-
}
|
1102
|
-
|
1103
|
-
void some_application_extension_callback()
|
1104
|
-
{
|
1105
|
-
// Need to initialize the stack here, because we don't know if
|
1106
|
-
// we are at the same stack depth as when the VM was initialized
|
1107
|
-
vm->init_stack();
|
1108
|
-
|
1109
|
-
// Now do some work...
|
1110
|
-
obj->call("some_callback_function")
|
1111
|
-
}
|
1112
|
-
\endcode
|
1113
|
-
|
1114
|
-
Be aware that initializing the Ruby VM can cause a call to exit() if
|
1115
|
-
certain command-line options are specified. This has two implications:
|
1116
|
-
|
1117
|
-
\li an application that constructs a Ruby VM may terminate
|
1118
|
-
unexpectedly if the options passed to the interpreter are not tightly
|
1119
|
-
controlled (a security issue), and
|
1120
|
-
|
1121
|
-
\li an application that constructs a Ruby VM should not have any
|
1122
|
-
objects with nontrivial destructors on the stack when the VM is
|
1123
|
-
created, otherwise those objects might not get correctly destructed.
|
1124
|
-
|
1125
1055
|
vim:ft=cpp:tw=72:ts=2:sw=2:fo=cqrtn:noci:si
|