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