I am trying to create a new class which inherits from another class someone else made, but I don't understand the way the class is made, and can't figure out how to make my new class.
Each class is in a seperate .lua
file.
The base class looks like this:
local Base = {}
local function new (_, _type, _subtype)
local new_base = {}
local properties = {
Type = {
get = function ()
return _type
end
},
Subtype = {
get = function ()
return _subtype
end
}
}
setmetatable( new_base, {
__index = function (_, key)
return (properties[key] and properties[key].get()) or Base[key]
end,
__newindex = function (_, key, value)
if properties[key] and properties[key].set then
properties[key].set( value )
end
end,
} )
return new_base
end
setmetatable( Base, {
__call = new,
} )
return Base
Then what I think is a subclass is created from the base class like so:
local Base = require( "vyzor.base" )
local MiniConsole = Base( "Component", "MiniConsole" )
local function new (_, name, init_x, init_y, init_width, init_height, word_wrap, font_size)
local new_console = {}
<other local variables>
local function updateAbsolutes ()
<does stuff>
end
local properties = {
Name = {
get = function ()
return name
end
},
Container = {
get = function ()
return container
end,
set = function (value)
if value.Type == "Frame" then
container = value
end
end,
<and so on>
end
function new_console:Echo (text)
echo( name, text )
end
<other functions>
setmetatable( new_console, {
__index = function (_, key)
return (properties[key] and properties[key].get()) or MiniConsole[key]
end,
__newindex = function (_, key, value)
if properties[key] and properties[key].set then
properties[key].set( value )
end
end,
} )
master_list[name] = new_console
return new_console
end
setmetatable( MiniConsole, {
__index = getmetatable(MiniConsole).__index,
__call = new,
} )
return MiniConsole
How would I make a class from the MiniConsole class that for example has a new function and variable, and also shares the same properties table from Miniconsole with some more additions:
I think it should start something like this?
local function new(_, name, title, init_x, init_y, init_width, init_height, word_wrap, font_size)
local new_console = MiniConsole(name, init_x, init_y, init_width, init_height, word_wrap, font_size)
Everything I have tried ends up giving me a "circular require or other error" error when I try to pcall it to use it elsewhere.