Initial commit
This commit is contained in:
53
src/types/types.lua
Normal file
53
src/types/types.lua
Normal file
@@ -0,0 +1,53 @@
|
||||
-- Copyright 2023 <omicron.me@protonmail.com>
|
||||
--
|
||||
-- This file is part of Omicron Frames
|
||||
--
|
||||
-- Omicron Frames is free software: you can redistribute it and/or modify it
|
||||
-- under the terms of the GNU General Public License as published by the Free
|
||||
-- Software Foundation, either version 3 of the License, or (at your option)
|
||||
-- any later version.
|
||||
--
|
||||
-- Omicron Frames is distributed in the hope that it will be useful, but
|
||||
-- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
-- more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License along with
|
||||
-- Omicron Frames. If not, see <https://www.gnu.org/licenses/>.
|
||||
local omif = select(2, ...)
|
||||
|
||||
local types = omif.GetModule("types")
|
||||
|
||||
-- Create any class, possibly top level
|
||||
local function CreateClassRaw(name, parent)
|
||||
local c = {}
|
||||
c.__typeInfo = {
|
||||
name = name,
|
||||
class = c,
|
||||
parent = parent
|
||||
}
|
||||
c.__index = c
|
||||
if parent ~= nil then
|
||||
setmetatable(c, parent)
|
||||
end
|
||||
return c
|
||||
end
|
||||
|
||||
types.Object = CreateClassRaw("Object")
|
||||
|
||||
-- Create a new class, eventually rooted at Object
|
||||
function types.CreateClass(name, parent)
|
||||
return CreateClassRaw(name, parent or types.Object)
|
||||
end
|
||||
|
||||
-- Return true if a is derived from b or if a is b
|
||||
function types.IsDerivedFrom(a, b)
|
||||
local current = a
|
||||
repeat
|
||||
if current == b then
|
||||
return true
|
||||
end
|
||||
current = current.__typeInfo.parent
|
||||
until current == nil;
|
||||
return false
|
||||
end
|
Reference in New Issue
Block a user