| -- This file illustrates the proxy class C++ interface generated by SWIG. | |
| require("example") | |
| -- ----- Object creation ----- | |
| print("Creating some objects:") | |
| local cc = example.Circle(10) | |
| local c = example.ShapePtr(cc) | |
| print(" Created circles", c) | |
| local ss = example.Square(10) | |
| local s = example.ShapePtr(ss) | |
| print(" Created square", s) | |
| -- ----- Access a static member ----- | |
| print(string.format("\nA total of %d shapes were created", example.Shape.nshapes)) | |
| -- ----- Member data access ----- | |
| -- Set the location of the object | |
| c.x = 20 | |
| c.y = 30 | |
| s.x = -10 | |
| s.y = 5 | |
| print("\nHere is their current position:") | |
| print(string.format(" Circle = (%f, %f)", c.x, c.y)) | |
| print(string.format(" Square = (%f, %f)", s.x, s.y)) | |
| -- ----- Call some methods ----- | |
| print("\nHere are some properties of the shapes:") | |
| for _, o in ipairs({c, s}) do | |
| print(" ", o) | |
| print(" area =", o:area()) | |
| print(" perimeter =", o:perimeter()) | |
| end | |
| print("\nGuess I'll clean up now") | |
| c=nil | |
| s=nil | |
| cc=nil | |
| ss=nil | |
| -- Note: this invokes the virtual destructors | |
| collectgarbage() -- performs a full garbage-collection cycle. | |
| print(string.format("%d shapes remain", example.Shape.nshapes)) | |
| print("Goodbye") |