diff options
Diffstat (limited to 'examples/oop_example.lua')
-rw-r--r-- | examples/oop_example.lua | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/examples/oop_example.lua b/examples/oop_example.lua index 45da36e..712387b 100644 --- a/examples/oop_example.lua +++ b/examples/oop_example.lua @@ -1,7 +1,15 @@ -a = nerv.Point() -print(a:get_sinx()) -a:set_x(3.14) -print(a:get_sinx()) -print(a[2]) -a[2] = 3 -print(a[2]) +p = nerv.Point(0, 0) -- create a Point instance +print(p) +print(p:norm()) -- get 2-norm of the Point +p:set_x(1.0) +p:set_y(2.0) +print(p:norm()) -- get 2-norm of the Point + +p = nerv.BetterPoint(1, 2) +print(p) +print(p:norm()) --get 1-norm of the Point + +-- create a subclass using lua +local EvenBetterPoint = nerv.class('nerv.EvenBetterPoint', 'nerv.BetterPoint') +bp = nerv.EvenBetterPoint(1, 2) +print(p:norm()) |