From 4b85302cf52bef823a13ceecf1fa467765f2e36e Mon Sep 17 00:00:00 2001 From: Logan Johnson Date: Wed, 12 Nov 2003 20:16:06 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5307 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Doc/Manual/Ruby.html | 152 +++++++------------------------------- 1 file changed, 25 insertions(+), 127 deletions(-) diff --git a/SWIG/Doc/Manual/Ruby.html b/SWIG/Doc/Manual/Ruby.html index 7405b8216..331680632 100644 --- a/SWIG/Doc/Manual/Ruby.html +++ b/SWIG/Doc/Manual/Ruby.html @@ -67,7 +67,6 @@
  • Operator overloading
  • Advanced Topics @@ -732,19 +731,19 @@ All of the usual Ruby utility methods work normally:
    -irb(main):001:0> b = Bar.new
    +irb(main):001:0> c = Child.new
     #<Bar:0x4016efd4>
    -irb(main):002:0> b.instance_of? Bar
    +irb(main):002:0> c.instance_of? Child
     true
    -irb(main):003:0> b.instance_of? Foo
    +irb(main):003:0> b.instance_of? Parent
     false
    -irb(main):004:0> b.is_a? Bar
    +irb(main):004:0> b.is_a? Child
     true
    -irb(main):005:0> b.is_a? Foo
    +irb(main):005:0> b.is_a? Parent
     true
    -irb(main):006:0> Bar < Foo
    +irb(main):006:0> Child < Parent
     true
    -irb(main):007:0> Bar > Foo
    +irb(main):007:0> Child > Parent
     false
     
    @@ -1433,7 +1432,7 @@ following in an interface file: try { $action } - catch (RangeError) { + catch (const RangeError&) { static VALUE cpperror = rb_define_class("CPPError", rb_eStandardError); rb_raise(cpperror, "Range error."); } @@ -1460,7 +1459,7 @@ exception handler to only apply to specific methods like this: try { $action } - catch (RangeError) { + catch (const RangeError&) { static VALUE cpperror = rb_define_class("CPPError", rb_eStandardError); rb_raise(cpperror, "Range error in getitem."); } @@ -1470,7 +1469,7 @@ exception handler to only apply to specific methods like this: try { $action } - catch (RangeError) { + catch (const RangeError&) { static VALUE cpperror = rb_define_class("CPPError", rb_eStandardError); rb_raise(cpperror, "Range error in setitem."); } @@ -1488,72 +1487,11 @@ exception handling. See the chapter on Customizati Features for more examples.

    -When raising a Ruby exception from C, use the rb_raise() +When raising a Ruby exception from C/C++, use the rb_raise() function as shown above. The first argument passed to rb_raise() is the exception type. You can raise a custom exception type (like the cpperror example -shown above) or one of the built-in Ruby exception types, listed here: - -

    -
    -rb_eException
    -rb_eStandardError
    -rb_eSystemExit
    -rb_eInterrupt
    -rb_eSignal
    -rb_eFatal
    -rb_eArgError
    -rb_eEOFError
    -rb_eIndexError
    -rb_eRangeError
    -rb_eIOError
    -rb_eRuntimeError
    -rb_eSecurityError
    -rb_eSystemCallError
    -rb_eTypeError
    -rb_eZeroDivError
    -rb_eNotImpError
    -rb_eNoMemError
    -rb_eNoMethodError
    -rb_eFloatDomainError
    -
    -rb_eScriptError
    -rb_eNameError
    -rb_eSyntaxError
    -rb_eLoadError
    -
    -
    -
    - -These exceptions are actually organized into an hierarchy as shown below. - -
    -
    -Exception          - rb_eException
    -Fatal              - rb_eFatal
    -Interrupt          - rb_eInterrupt
    -NoMemoryError      - rb_eNoMemError
    -Signal             - rb_eSignal
    -ScriptError        - rb_eScriptError
    -  LoadError        - rb_eLoadError
    -  NameError        - rb_eNameError
    -  NotImpError      - rb_eNotImpError
    -  SyntaxError      - rb_eSyntaxError
    -  NoMethodError    - rb_eNoMethodError
    -StandardError      - rb_eStandardError
    -  ArgError         - rb_eArgError
    -  FloatDomainError - rb_eFloatDomainError
    -  IndexError       - rb_eIndexError
    -  IOError          - rb_eIOError
    -    EOFError       - rb_eEOFError
    -  SecurityError    - rb_eSecurityError
    -  RuntimeError     - rb_eRuntimeError
    -  SystemCallError  - rb_eSystemCallError
    -  TypeError        - rb_eTypeError
    -  ZeroDivError     - rb_eZeroDivError
    -  RangeError       - rb_eRangeError
    -SystemExit
    -
    -
    +shown above) or one of the built-in Ruby exception types. For a list of the standard +Ruby exception classes, consult a Ruby reference such as Programming Ruby.

    20.6 Typemaps

    @@ -1578,12 +1516,13 @@ a specific C datatype. For example, to convert integers from Ruby to C, you might define a typemap like this:

    +%module example
     
    -%module Example
     %typemap(in) int {
       $1 = (int) NUM2INT($input);
       printf("Received an integer : %d\n",$1);
     }
    +
     extern int fact(int n);
     
    @@ -1596,13 +1535,16 @@ code a number of special variables prefaced by a $ are used. The $1 variable is placeholder for a local variable of type int. The $input variable is the input Ruby object.

    -When this example is compiled into a Ruby module, it operates as follows: +When this example is compiled into a Ruby module, the following sample code:

     require 'example'
    +
     puts Example.fact(6)
    ----- Prints
    +
    +prints the result: +
     Received an integer : 6
     720
     
    @@ -1817,7 +1759,7 @@ The Ruby name of the wrapper function being created. When you write a typemap, you usually have to work directly with Ruby objects. The following functions may prove to be useful. (These functions plus many -more can be found in the "Programming Ruby" book written by David Thomas +more can be found in Programming Ruby, by David Thomas and Andrew Hunt.)

    @@ -2411,13 +2353,10 @@ __ge__ - >= Note that although SWIG supports the __eq__ magic method name for defining an equivalence operator, there is no separate method for handling inequality since Ruby parses the expression a != b as !(a == b). -

    20.7.1 An example (putting everything together)

    +

    20.7.1 Example: Using Standard SWIG Library Modules

    - -One way to illustrate the use of operator overloading, as well as the wrapping -of templates (see the "SWIG and C++" section on -templates) is shown in the following .i example is used, given an -STL vector class: +The following example illustrates how to use two of the standard SWIG library modules +(the std_string.i and std_vector.i modules).

    @@ -2474,48 +2413,7 @@ irb(main):014:0> s_list[0]
     

    -

    20.7.2 Expanding the example

    - - -To expand on the previous example, the following shows how to create a vector -of a C++ class object: - -
    -class CPP_Object;
    -%template(CPP_ObjectPtrVector)  vector<CPP_Object*>;
    -
    -%extend CPP_ObjectPtrVector {
    -  void each () {
    -    CPP_ObjectPtrVector::iterator i1 = self->begin();
    -    CPP_ObjectPtrVector::iterator i1end = self->end();
    -    for ( ; i1 != i1end; i1++) 
    -      rb_yield(Data_Wrap_Struct(cCPP_Object.klass, NULL, NULL, *i1));
    -  }
    -}
    -
    - -Notice that the SWIG interface has created a cCPP_Object that is of -type swig_class. This is an implementation detail that only works for -SWIG 1.3.11; for previous versions of SWIG the data type of -cCPP_Object was VALUE. - -

    -

    -typedef struct {
    -  VALUE  klass;
    -  void (*mark)(void *);
    -  void (*destroy)(void *);
    -} swig_class;
    -
    - -Thus, to access the pointer to the CPP_Object, the variable -klass is used.

    - -Also note that the call to Data_Wrap_Struct() sets the free -parameter for CPP_Object to NULL. That is done because C++, - owns the object and thus should free it, not Ruby. - -

    20.7.3 STL Vector to Ruby Array

    +

    20.7.3 Example: STL Vector to Ruby Array

    Another use for macros and type maps is to create a Ruby array from a STL