aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorTed Yin <ted.sybil@gmail.com>2015-05-31 22:20:19 +0800
committerTed Yin <ted.sybil@gmail.com>2015-05-31 22:20:19 +0800
commitae05d335f247ef2e83ad29ed9dca76260a9d7dff (patch)
tree51ce108a625ba1f72d28e589bac7b752e4eb2e05 /doc
parentab12a9583bdd39884fde9bc2444e6fd1bc5f518e (diff)
parent00c724864321be2b77891154d73fef18871182e1 (diff)
Merge pull request #10 from cloudygoose/master
add more contents to doc
Diffstat (limited to 'doc')
-rw-r--r--doc/nerv.md10
-rw-r--r--doc/nerv_class.md36
2 files changed, 46 insertions, 0 deletions
diff --git a/doc/nerv.md b/doc/nerv.md
index 85a86ca..22b4072 100644
--- a/doc/nerv.md
+++ b/doc/nerv.md
@@ -1,5 +1,15 @@
#The Nerv utility functions#
Part of the [Nerv](../README.md) toolkit.
##Methods##
+* __string = nerv.typename(obj a)__
+A registered function, the original function is `luaT_lua_typename`. In some cases if you call `type(a)` for object of some class in __Nerv__(like __Nerv.CuMatrix__) it will only return "userdata"(because it is created in C), in this case you can use this method to get its type.
+
+---
+
+* __metatable = nerv.getmetatable(string tname)__
+A registered function, the original function is `luaT_lua_getmetatable`. `tname` should be a class name that has been registered in __luaT__.
+
+* __metatable = nerv.newmetatable(string tname, string parenttname, function constructor, function destructor, function factory)__
+A registered function, the original function is `luaT_newmetatable`, it returns the metatable of the created class by the name `tname`.
* __string = nerv.setmetatable(table self, string tname)__
A registered function, the original function is `luaT_lua_setmetatable`. It assigns the metatable registered in __luaT__ by the name *tname* to the table *self*. And return *tname* to user.
diff --git a/doc/nerv_class.md b/doc/nerv_class.md
new file mode 100644
index 0000000..99f63e7
--- /dev/null
+++ b/doc/nerv_class.md
@@ -0,0 +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