1 # Copyright (c) 2005-2007 Diego Pettenò <flameeyes@gmail.com>
3 # Permission is hereby granted, free of charge, to any person obtaining
4 # a copy of this software and associated documentation files (the
5 # "Software"), to deal in the Software without restriction, including
6 # without limitation the rights to use, copy, modify, merge,
7 # publish, distribute, sublicense, and/or sell copies of the Software,
8 # and to permit persons to whom the Software is furnished to do so,
9 # subject to the following conditions:
11 # The above copyright notice and this permission notice shall be
12 # included in all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 # FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20 # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 # Rust is a Ruby bindings generator, developed by Diego Pettenò
26 # <flameeyes@gmail.com>, based on a simpler Ruby bindings generator
27 # that was used for RubyTag++ and ruby-hunspell.
29 # The original bindings generator was designed to permit a 1:1 mapping
30 # between C++ classes and Ruby classes, as otherwise writing Ruby
31 # bindings for a C++-based library would have consisted of a long
32 # series of generic functions to convert the types from one language
33 # to the other and to call the methods.
35 # Most C bindings, instead, either writes a lot of C code to create
36 # "fake" Classes out of a vaguely object-oriented C API, or simply
37 # create a module where to put all the C functions to call.
39 # The objective of Rust is to allow the description of a C or C++
40 # interface, through the creation of 1:1 class mappings or the design
41 # of "fake" classes out of C functions, without the need to actually
42 # write all the generic code, as that does not really change beside
43 # names, types and parameters.
46 # The Template singleton class is used to simulate a big hash of
47 # templates, loaded with the data from the templates/ subdirectory.
48 # In truth the templates are loaded only when requested, removing
49 # the one-line comments found inside the files (as they are usually
50 # just for documenting that particular template).
53 @tpls_dir = (Pathname.new File.dirname(__FILE__)) + "rust/templates"
55 def Templates.[](name)
56 return @cache[name].dup if @cache[name]
58 pn = @tpls_dir + "#{name}.rusttpl"
59 raise "Template #{name} not found." unless pn.exist?
61 @cache[name] = pn.read.gsub(/\/\/.*$\n?/, '')
62 return @cache[name].dup
67 require 'rust/bindings'