diff options
author | cloudygoose <[email protected]> | 2015-05-31 15:40:37 +0800 |
---|---|---|
committer | cloudygoose <[email protected]> | 2015-05-31 15:40:37 +0800 |
commit | 00c724864321be2b77891154d73fef18871182e1 (patch) | |
tree | 51ce108a625ba1f72d28e589bac7b752e4eb2e05 /doc | |
parent | d195028baca29cb5ca1f90df413b3d0a8df79857 (diff) |
doc change
Diffstat (limited to 'doc')
-rw-r--r-- | doc/nerv_class.md | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/doc/nerv_class.md b/doc/nerv_class.md index 3c3d09e..99f63e7 100644 --- a/doc/nerv_class.md +++ b/doc/nerv_class.md @@ -1,3 +1,36 @@ #The Nerv OOP# Part of the [Nerv](../README.md) toolkit. ##Methods## +* __metatable mt, metatable mpt = nerv.class(string tname, string parenttname)__ +This method is used to create a class by the name `tname`, which inherits `parenttname` in __Nerv__, then you create a new instance of this class by calling `obj=tname(...)`. The `tname.__init(...)` method(if defined) will be called in the constructing. The metatable of the class and its parent class will be returned. + +##Examples## +* This example implements a simple `nerv.Counter` class which is inherited by `nerv.BetterCounter`. + +``` +do + nerv.class("nerv.Counter") + function nerv.Counter:__init(c) + if (c) then + self.c = c + else + self.c = 0 + end + end +end +do + local mt, mpt = nerv.class("nerv.BetterCounter", "nerv.Counter") + function nerv.BetterCounter:__init(c, bc) + mpt.__init(self, c) + if (bc) then + self.bc = bc + else + self.bc = 0 + end + end +end +c1 = nerv.Counter(1) +print(c1.c) +bc1 = nerv.BetterCounter(1, 1) +print(bc1.c, bc1.bc) +```
\ No newline at end of file |