projects
/
project
/
luci.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
ba6928d
)
Optimized luci.util.class
author
Steven Barth
<steven@midlink.org>
Wed, 10 Sep 2008 12:22:29 +0000
(12:22 +0000)
committer
Steven Barth
<steven@midlink.org>
Wed, 10 Sep 2008 12:22:29 +0000
(12:22 +0000)
libs/core/luasrc/util.lua
patch
|
blob
|
history
diff --git
a/libs/core/luasrc/util.lua
b/libs/core/luasrc/util.lua
index 5f9c609f65c8da89b462dbb7326ceea9259faaa9..c84df1a170f46f41d04cc1c8ac0cff72ed2cccd0 100644
(file)
--- a/
libs/core/luasrc/util.lua
+++ b/
libs/core/luasrc/util.lua
@@
-59,6
+59,17
@@
end
-- Class helper routines
--
-- 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.
--- 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)
-- @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.
end
--- Test whether the given object is an instance of the given class.