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