mirror of
https://github.com/kikito/middleclass.git
synced 2024-11-08 09:34:22 +00:00
made class non-global
This commit is contained in:
parent
491eb44628
commit
88e84d13c2
@ -135,11 +135,6 @@ function Object:initialize() end
|
|||||||
|
|
||||||
function Object:__tostring() return "instance of " .. tostring(self.class) end
|
function Object:__tostring() return "instance of " .. tostring(self.class) end
|
||||||
|
|
||||||
function class(name, super, ...)
|
|
||||||
super = super or Object
|
|
||||||
return super:subclass(name, ...)
|
|
||||||
end
|
|
||||||
|
|
||||||
function instanceOf(aClass, obj)
|
function instanceOf(aClass, obj)
|
||||||
if type(aClass) ~= 'table' or type(obj) ~= 'table' or not obj.class then return false end
|
if type(aClass) ~= 'table' or type(obj) ~= 'table' or not obj.class then return false end
|
||||||
if obj.class == aClass then return true end
|
if obj.class == aClass then return true end
|
||||||
@ -157,4 +152,11 @@ function includes(mixin, aClass)
|
|||||||
return includes(mixin, aClass.super)
|
return includes(mixin, aClass.super)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function middleclass.class(name, super, ...)
|
||||||
|
super = super or Object
|
||||||
|
return super:subclass(name, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
setmetatable(middleclass, { __call = function(_, ...) return middleclass.class(...) end })
|
||||||
|
|
||||||
return middleclass
|
return middleclass
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
require 'middleclass'
|
local class = require 'middleclass'
|
||||||
|
|
||||||
context('Object', function()
|
context('Object', function()
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
require 'middleclass'
|
local class = require 'middleclass'
|
||||||
|
|
||||||
context('class()', function()
|
context('class()', function()
|
||||||
|
|
||||||
@ -9,31 +9,19 @@ context('class()', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
context('when given a name', function()
|
context('when given a name', function()
|
||||||
local TheClass
|
test('the resulting class has the correct name and Object as its superclass', function()
|
||||||
|
local TheClass = class('TheClass')
|
||||||
before(function()
|
|
||||||
TheClass = class('TheClass')
|
|
||||||
end)
|
|
||||||
|
|
||||||
test('the resulting class has the correct name', function()
|
|
||||||
assert_equal(TheClass.name, 'TheClass')
|
assert_equal(TheClass.name, 'TheClass')
|
||||||
end)
|
|
||||||
|
|
||||||
test('the resulting class has Object as its superclass', function()
|
|
||||||
assert_equal(TheClass.super, Object)
|
assert_equal(TheClass.super, Object)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
context('when given a name and a superclass', function()
|
context('when given a name and a superclass', function()
|
||||||
local TheSuperClass = class('TheSuperClass')
|
test('the resulting class has the correct name and superclass', function()
|
||||||
local TheSubClass = class('TheSubClass', TheSuperClass)
|
local TheSuperClass = class('TheSuperClass')
|
||||||
|
local TheSubClass = class('TheSubClass', TheSuperClass)
|
||||||
test('the resulting class has the correct name', function()
|
|
||||||
assert_equal(TheSubClass.name, 'TheSubClass')
|
assert_equal(TheSubClass.name, 'TheSubClass')
|
||||||
end)
|
assert_equal(TheSubClass.super, TheSuperClass)
|
||||||
|
|
||||||
test('the resulting class has the correct superclass', function()
|
|
||||||
assert_equal(TheSubClass.super, TheSuperClass)
|
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
require 'middleclass'
|
local class = require 'middleclass'
|
||||||
|
|
||||||
context('A Class', function()
|
context('A Class', function()
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
require 'middleclass'
|
local class = require 'middleclass'
|
||||||
|
|
||||||
context('includes', function()
|
context('includes', function()
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
require 'middleclass'
|
local class = require 'middleclass'
|
||||||
|
|
||||||
context('instanceOf', function()
|
context('instanceOf', function()
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
require 'middleclass'
|
local class = require 'middleclass'
|
||||||
|
|
||||||
context('An instance', function()
|
context('An instance', function()
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
require 'middleclass'
|
local class = require 'middleclass'
|
||||||
|
|
||||||
context('Metamethods', function()
|
context('Metamethods', function()
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
require 'middleclass'
|
local class = require 'middleclass'
|
||||||
|
|
||||||
context('A Mixin', function()
|
context('A Mixin', function()
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
require 'middleclass'
|
local class = require 'middleclass'
|
||||||
|
|
||||||
context('subclassOf', function()
|
context('subclassOf', function()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user