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

/trunk/Examples/go/variables/runme.go

#
Go | 67 lines | 47 code | 13 blank | 7 comment | 0 complexity | c2993f33ee08145fba560cd385417f93 MD5 | raw file
 1// This example illustrates global variable access from Go.
 2
 3package main
 4
 5import (
 6	"fmt"
 7	"./example"
 8)
 9
10func main() {
11	// Try to set the values of some global variables
12
13	example.SetIvar(42)
14	example.SetSvar(-31000)
15	example.SetLvar(65537)
16	example.SetUivar(123456)
17	example.SetUsvar(61000)
18	example.SetUlvar(654321)
19	example.SetScvar(-13)
20	example.SetUcvar(251)
21	example.SetCvar('S')
22	example.SetFvar(3.14159)
23	example.SetDvar(2.1828)
24	example.SetStrvar("Hello World")
25	example.SetIptrvar(example.New_int(37))
26	example.SetPtptr(example.New_Point(37, 42))
27	example.SetName("Bill")
28
29	// Now print out the values of the variables
30
31	fmt.Println("Variables (values printed from Go)")
32
33	fmt.Println("ivar      =", example.GetIvar())
34	fmt.Println("svar      =", example.GetSvar())
35	fmt.Println("lvar      =", example.GetLvar())
36	fmt.Println("uivar     =", example.GetUivar())
37	fmt.Println("usvar     =", example.GetUsvar())
38	fmt.Println("ulvar     =", example.GetUlvar())
39	fmt.Println("scvar     =", example.GetScvar())
40	fmt.Println("ucvar     =", example.GetUcvar())
41	fmt.Println("fvar      =", example.GetFvar())
42	fmt.Println("dvar      =", example.GetDvar())
43	fmt.Printf("cvar      = %c\n", example.GetCvar())
44	fmt.Println("strvar    =", example.GetStrvar())
45	fmt.Println("cstrvar   =", example.GetCstrvar())
46	fmt.Println("iptrvar   =", example.GetIptrvar())
47	fmt.Println("name      =", example.GetName())
48	fmt.Println("ptptr     =", example.GetPtptr(), example.Point_print(example.GetPtptr()))
49	fmt.Println("pt        =", example.GetPt(), example.Point_print(example.GetPt()))
50
51	fmt.Println("\nVariables (values printed from C)")
52
53	example.Print_vars()
54
55	// This line would not compile: since status is marked with
56	// %immutable, there is no SetStatus function.
57	// fmt.Println("\nNow I'm going to try and modify some read only variables")
58	// example.SetStatus(0)
59
60	fmt.Println("\nI'm going to try and update a structure variable.\n")
61
62	example.SetPt(example.GetPtptr())
63
64	fmt.Println("The new value is")
65	example.Pt_print()
66	fmt.Println("You should see the value", example.Point_print(example.GetPtptr()))
67}