summaryrefslogtreecommitdiff
path: root/class_example.lua
diff options
context:
space:
mode:
Diffstat (limited to 'class_example.lua')
-rw-r--r--class_example.lua24
1 files changed, 24 insertions, 0 deletions
diff --git a/class_example.lua b/class_example.lua
new file mode 100644
index 0000000..ab69b70
--- /dev/null
+++ b/class_example.lua
@@ -0,0 +1,24 @@
+A = nerv.class()
+function A:_init(x)
+ self.x = x
+end
+function A:f()
+ return self.x
+end
+
+function A:g()
+ return self.x + 1
+end
+
+B = nerv.class(A)
+
+function B:f()
+ return self.x * self.x
+end
+
+a = A(3)
+b = B(3)
+print(a:f())
+print(b:f())
+print(b:g())
+