PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/ruby/constants/index.html

#
HTML | 64 lines | 47 code | 17 blank | 0 comment | 0 complexity | 6af79a8a3f27f2e261ebb668e1985785 MD5 | raw file
 1<html>
 2<head>
 3<title>SWIG:Examples:ruby:constants</title>
 4</head>
 5
 6<body bgcolor="#ffffff">
 7
 8<tt>SWIG/Examples/ruby/constants/</tt>
 9<hr>
10
11<H2>Wrapping C Constants</H2>
12
13<p>
14When SWIG encounters C preprocessor macros and C declarations that look like constants,
15it creates Ruby constants with an identical value.  Click <a href="example.i">here</a>
16to see a SWIG interface with some constant declarations in it.
17
18<h2>Accessing Constants from Ruby</h2>
19
20Click <a href="run.rb">here</a> to see a script that prints out the values
21of the constants contained in the above file.
22
23<h2>Key points</h2>
24
25<ul>
26<li>The values of preprocessor macros are converted into Ruby constants.
27<li>Types are inferred by syntax (e.g., "3" is an integer and "3.5" is a float).
28<li>Character constants such as 'x' are converted into Ruby strings.
29<li>C string literals such as "Hello World" are converted into Ruby strings.
30<li>Macros that are not fully defined are simply ignored.  For example:
31<blockquote>
32<pre>
33#define EXTERN extern
34</pre>
35</blockquote>
36is ignored because SWIG has no idea what type of variable this would be.
37
38<p>
39<li>Expressions are allowed provided that all of their components are defined. Otherwise, the constant is ignored.
40
41<li>Certain C declarations involving 'const' are also turned into Ruby constants.
42
43<li>Constants that begin with lower case character are automatically capitalized.
44For example:
45<blockquote>
46<pre>
47const int     iconst = 37;
48</pre>
49</blockquote>
50is capitalized as <tt>Example::Iconst</tt> because Ruby constants name must begin
51with upper case character.
52
53<li>The constants that appear in a SWIG interface file do not have to appear in any sort
54of matching C source file since the creation of a constant does not require linkage
55to a stored value (i.e., a value held in a C global variable or memory location).
56
57
58</ul>
59
60<hr>
61
62
63</body>
64</html>