diff options
Diffstat (limited to 'acf/object.lua')
-rw-r--r-- | acf/object.lua | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/acf/object.lua b/acf/object.lua index 670a8bb..64fbb9c 100644 --- a/acf/object.lua +++ b/acf/object.lua @@ -1,11 +1,11 @@ --[[ -Copyright (c) 2012 Kaarle Ritvanen +Copyright (c) 2012-2013 Kaarle Ritvanen See LICENSE file for license details --]] -module(..., package.seeall) +local M = {} -function class(base) +function M.class(base) local cls = {} local mt = { @@ -17,7 +17,7 @@ function class(base) end } - if not base and Object then base = Object end + if not base and M.Object then base = M.Object end if base then cls._base = base mt.__index = base @@ -27,13 +27,13 @@ function class(base) end -Object = class() +M.Object = M.class() -function Object:init(...) end +function M.Object:init(...) end -function super(obj, cls) - assert(isinstance(obj, cls)) +function M.super(obj, cls) + assert(M.isinstance(obj, cls)) local mt = {} @@ -51,15 +51,18 @@ function super(obj, cls) end -function issubclass(cls1, cls2) +function M.issubclass(cls1, cls2) if cls1 == cls2 then return true end - if cls1._base then return issubclass(cls1._base, cls2) end + if cls1._base then return M.issubclass(cls1._base, cls2) end return false end -function isinstance(obj, cls) +function M.isinstance(obj, cls) if not obj or type(obj) ~= 'table' then return false end local mt = getmetatable(obj) if not mt then return false end - return type(obj) == 'table' and mt.class and issubclass(mt.class, cls) + return type(obj) == 'table' and mt.class and M.issubclass(mt.class, cls) end + + +return M |