diff options
author | Determinant <[email protected]> | 2015-05-24 19:02:09 +0800 |
---|---|---|
committer | Determinant <[email protected]> | 2015-05-24 19:02:09 +0800 |
commit | 39e1834c449a55a44e95f2cfb6b24887fd3cec70 (patch) | |
tree | 272cbd5da6ad2208a86b2b7e6c960127b3cfecbe /nerv.lua | |
parent | 63b529dc50ef0fc39e9279a976ab805ea9b11de7 (diff) |
add nerv.class and try to let Lua class inherit from ParamFile
Diffstat (limited to 'nerv.lua')
-rw-r--r-- | nerv.lua | 27 |
1 files changed, 26 insertions, 1 deletions
@@ -1,6 +1,6 @@ require 'libnerv' require 'matrix.init' -nerv.class = require 'pl.class' +-- nerv.class = require 'pl.class' nerv.utils = require 'pl.utils' function nerv.error(fmt, ...) @@ -10,3 +10,28 @@ end function nerv.error_method_not_implement() nerv.error("method not implemented"); end + +function nerv.class(tname, parenttname) + + local function constructor(...) + local self = {} + nerv.setmetatable(self, tname) + if self.__init then + self:__init(...) + end + return self + end + + local function factory() + local self = {} + nerv.setmetatable(self, tname) + return self + end + + local mt = nerv.newmetatable(tname, parenttname, constructor, nil, factory) + local mpt + if parenttname then + mpt = nerv.getmetatable(parenttname) + end + return mt, mpt +end |