PageRenderTime 16ms CodeModel.GetById 13ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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

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