PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/trunk/Examples/go/variables/index.html

#
HTML | 87 lines | 70 code | 17 blank | 0 comment | 0 complexity | 04c46a44628c4145a57310129a2d5b2a 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:go:variables</title>
  4. </head>
  5. <body bgcolor="#ffffff">
  6. <tt>SWIG/Examples/go/variables/</tt>
  7. <hr>
  8. <H2>Wrapping C Global Variables</H2>
  9. <p>
  10. When a C global variable appears in an interface file, SWIG provides
  11. getter and setter functions for the variable. The getter function is
  12. named <tt>Get</tt> followed by the capitalized name of the variable.
  13. The setter variable starts with <tt>Set</tt> instead. The getter
  14. function takes no parameters and returns the value of the variable.
  15. The setter function takes a single parameter with the same type as the
  16. variable, and returns nothing.
  17. <p>Click <a href="example.i">here</a> to see a SWIG interface with
  18. some variable declarations in it.
  19. <h2>Manipulating Variables from Go</h2>
  20. For example, if the package is called <tt>example</tt>, the global
  21. variable
  22. <blockquote>
  23. <pre>
  24. double foo;
  25. </pre>
  26. </blockquote>
  27. will be accessed from Go as
  28. <blockquote>
  29. <pre>
  30. example.GetFoo();
  31. example.SetFoo(12.3);
  32. </pre>
  33. </blockquote>
  34. Click <a href="runme.go">here</a> to see the example program that
  35. updates and prints out the values of the variables using this
  36. technique.
  37. <h2>Key points</h2>
  38. <ul>
  39. <li>The name of the variable is capitalized.
  40. <li>When a global variable has the type "<tt>char *</tt>", SWIG
  41. manages it as a character string.
  42. <li><tt>signed char</tt> and <tt>unsigned char</tt> are handled as
  43. small 8-bit integers.
  44. <li>String array variables such as '<tt>char name[256]</tt>' are
  45. managed as Go strings, but when setting the value, the result is
  46. truncated to the maximum length of the array. Furthermore, the string
  47. is assumed to be null-terminated.
  48. <li>When structures and classes are used as global variables, they are
  49. mapped into pointers. Getting the "value" returns a pointer to the
  50. global variable. Setting the value of a structure results in a memory
  51. copy from a pointer to the global.
  52. </ul>
  53. <h2>Creating read-only variables</h2>
  54. The <tt>%immutable</tt> and <tt>%mutable</tt> directives can be used
  55. to specify a collection of read-only variables. A read only variable
  56. will have a getter function but no setter function. For example:
  57. <blockquote>
  58. <pre>
  59. %immutable;
  60. int status;
  61. double blah;
  62. ...
  63. %mutable;
  64. </pre>
  65. </blockquote>
  66. The <tt>%immutable</tt> directive remains in effect until it is
  67. explicitly disabled using the <tt>%mutable</tt> directive.
  68. </body>
  69. </html>
  70. <hr>