diff options
author | Determinant <[email protected]> | 2015-05-25 16:55:58 +0800 |
---|---|---|
committer | Determinant <[email protected]> | 2015-05-25 16:55:58 +0800 |
commit | bc1e2c57b1f234d153254845d62994bcd1a6e42f (patch) | |
tree | b1f371eb3ebe97355d217288665a8fa15495cbfa /examples/oop_example.lua | |
parent | 7dadb31a364c3dbe30c05c9a9040c48f1d4a9095 (diff) |
rewrite the oop example
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()) |