summaryrefslogtreecommitdiffhomepage
path: root/libs/core
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-09-10 12:22:29 +0000
committerSteven Barth <steven@midlink.org>2008-09-10 12:22:29 +0000
commit9e2759ec348c4b44475fd594d91eab14e7e3220e (patch)
treecc56438bc70ab78c1b691762f2ee8022bbb07fd9 /libs/core
parentba6928dce0f136babb7184c0fdad8a205489995b (diff)
Optimized luci.util.class
Diffstat (limited to 'libs/core')
-rw-r--r--libs/core/luasrc/util.lua35
1 files changed, 15 insertions, 20 deletions
diff --git a/libs/core/luasrc/util.lua b/libs/core/luasrc/util.lua
index 5f9c609f6..c84df1a17 100644
--- a/libs/core/luasrc/util.lua
+++ b/libs/core/luasrc/util.lua
@@ -59,6 +59,17 @@ end
-- Class helper routines
--
+-- Instantiates a class
+local function _instantiate(class, ...)
+ local inst = setmetatable({}, {__index = class})
+
+ if inst.__init__ then
+ inst:__init__(...)
+ end
+
+ return inst
+end
+
--- Create a Class object (Python-style object model).
-- The class object can be instantiated by calling itself.
-- Any class functions or shared parameters can be attached to this object.
@@ -74,26 +85,10 @@ end
-- @see instanceof
-- @see clone
function class(base)
- local class = {}
-
- local create = function(class, ...)
- local inst = setmetatable({}, {__index = class})
-
- if inst.__init__ then
- inst:__init__(...)
- end
-
- return inst
- end
-
- local classmeta = {__call = create}
-
- if base then
- classmeta.__index = base
- end
-
- setmetatable(class, classmeta)
- return class
+ return setmetatable({}, {
+ __call = _instantiate,
+ __index = base
+ })
end
--- Test whether the given object is an instance of the given class.